Skip to content

Commit

Permalink
Add more pos tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandofpd committed Oct 8, 2023
1 parent ad36307 commit 2727c77
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CheckDollarInIdentifier extends MiniPhase:

private val allowedDefTermNames = List(
nme.DOLLAR_NEW,
nme.ANON_FUN,
).map(_.toString)

private def allowedTerms[T <: Tree](tree: T): List[String] =
Expand Down
64 changes: 63 additions & 1 deletion tests/pos/i18234.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ case class CaseClass(someField: Int) // error

class GoodClass

object GoodClass:
val companionObjectValue = 5
end GoodClass

class Class(
var goodMember: Int,
):
Expand All @@ -35,4 +39,62 @@ trait GoodTrait
class TestTraitUsage extends GoodTrait

package GoodPackage:
val goodVal = 1
val goodVal = 1


lazy val lazyVal = 23

val listWithAnonymousFunc = List(1, 2, 3).map(_ * 2).map((num) => num + 1)

object TestAnonymousClass:
trait SomeTrait:
def somefunc(): String

val anObject = new SomeTrait:
override def somefunc(): String = "hello"
end TestAnonymousClass

val partialFunc: PartialFunction[Int, Int] =
case x if x <= 0 => Math.abs(x)

val anotherPartialFunc: PartialFunction[String, String] = { case x @ "abc" => x }

object TestInline:
import scala.quoted.* // imports Quotes, Expr

inline val pi = 3.141592653589793

inline def power(inline x: Double, inline n: Int) =
${ powerCode('x, 'n) }


def pow(x: Double, n: Int): Double =
if n == 0 then 1 else x * pow(x, n - 1)

def powerCode(
x: Expr[Double],
n: Expr[Int]
)(using Quotes): Expr[Double] =
val value: Double = pow(x.valueOrAbort, n.valueOrAbort)
Expr(value)

end TestInline

object TestGivens:
trait Showable[A]:
extension (a: A) def show: String
case class Person(firstName: String, lastName: String)
// anonymous given
given Showable[Person] with
extension (p: Person) def show: String =
s"${p.firstName} ${p.lastName}"
// named given
given caseClassShowable: Showable[CaseClass] with
extension (c: CaseClass) def show: String = s"number ${c.someField}"
def showMe[T: Showable](t: T) = t.show
showMe(Person("John", "Doe"))
showMe(CaseClass(42))

given Int = 42
def showUsing(using someNumber: Int) = CaseClass(someNumber)
end TestGivens

0 comments on commit 2727c77

Please sign in to comment.