Skip to content

Commit 27c6866

Browse files
committed
Various tests and test-fixes for erasedDefinitions feature
- Change tests in accordance to new erased parameter Quotes API - Add quotes test for some erased parameters APIs - Add tests for Reflect `hasErasedParams`/`erasedParams` and creating an erased method
1 parent c52881f commit 27c6866

File tree

26 files changed

+152
-22
lines changed

26 files changed

+152
-22
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ object desugar {
18341834
cpy.ByNameTypeTree(parent)(annotate(tpnme.retainsByName, restpt))
18351835
case _ =>
18361836
annotate(tpnme.retains, parent)
1837-
case f: FunctionWithMods if f.erasedParams.contains(true) => makeFunctionWithValDefs(f, pt)
1837+
case f: FunctionWithMods if f.hasErasedParams => makeFunctionWithValDefs(f, pt)
18381838
}
18391839
desugared.withSpan(tree.span)
18401840
}

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
8080
class FunctionWithMods(args: List[Tree], body: Tree, val mods: Modifiers, val erasedParams: List[Boolean])(implicit @constructorOnly src: SourceFile)
8181
extends Function(args, body) {
8282
assert(args.length == erasedParams.length)
83+
84+
def hasErasedParams = erasedParams.contains(true)
8385
}
8486

8587
/** A polymorphic function type */

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,11 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
648648
case tp: MethodType =>
649649
def paramErasure(tpToErase: Type) =
650650
erasureFn(sourceLanguage, semiEraseVCs, isConstructor, isSymbol, wildcardOK)(tpToErase)
651-
val (names, formals0) = if (tp.hasErasedParams)
651+
val (names, formals0) = if tp.hasErasedParams then
652652
tp.paramNames
653653
.zip(tp.paramInfos)
654654
.zip(tp.erasedParams)
655-
.flatMap((p, e) => if e then None else Some(p))
655+
.collect{ case (param, isErased) if !isErased => param }
656656
.unzip
657657
else (tp.paramNames, tp.paramInfos)
658658
val formals = formals0.mapConserve(paramErasure)

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3734,7 +3734,7 @@ object Types {
37343734
val params = if (hasErasedParams)
37353735
tp.paramInfos
37363736
.zip(tp.erasedParams)
3737-
.flatMap((p, e) => if e then None else Some(p))
3737+
.collect { case (param, isErased) if !isErased => param }
37383738
else tp.paramInfos
37393739
resultSignature.prependTermParams(params, sourceLanguage)
37403740
case tp: PolyType =>

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
235235
changePrec(GlobalPrec) {
236236
"("
237237
~ keywordText("using ").provided(tp.isContextualMethod)
238-
~ keywordText("erased ").provided(tp.isErasedMethod)
239238
~ keywordText("implicit ").provided(tp.isImplicitMethod && !tp.isContextualMethod)
240239
~ paramsText(tp)
241240
~ ")"

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
287287
case tp @ FunProto(args, resultType) =>
288288
"[applied to ("
289289
~ keywordText("using ").provided(tp.isContextualMethod)
290-
~ keywordText("erased ").provided(tp.isErasedMethod)
291290
~ argsTreeText(args)
292291
~ ") returning "
293292
~ toText(resultType)

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,9 +1584,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
15841584
def isErased: Boolean = false
15851585

15861586
def erasedArgs: List[Boolean] =
1587-
self.map(param => param.tpe.hasAnnotation(dotc.core.Symbols.defn.ErasedParamAnnot))
1587+
self.map(_.symbol.is(dotc.core.Flags.Erased))
15881588
def hasErasedArgs: Boolean =
1589-
self.exists(param => param.tpe.hasAnnotation(dotc.core.Symbols.defn.ErasedParamAnnot))
1589+
self.exists(_.symbol.is(dotc.core.Flags.Erased))
15901590
end TermParamClauseMethods
15911591

15921592
type TypeParamClause = List[tpd.TypeDef]

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
23742374
/** Is this a given parameter clause `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
23752375
def isGiven: Boolean
23762376
/** Is this a erased parameter clause `(erased x1: X1, ..., xn: Xn)` */
2377-
// TODO:deprecate in 3.4 and stabilize `erasedParams` and `hasErasedParams`.
2377+
// TODO:deprecate in 3.4 and stabilize `erasedArgs` and `hasErasedArgs`.
23782378
// @deprecated("Use `hasErasedArgs`","3.4")
23792379
def isErased: Boolean
23802380

tests/neg/safeThrowsStrawman2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def bar(x: Boolean)(using CanThrow[Fail]): Int =
2424
val x = new CanThrow[Fail]() // OK, x is erased
2525
val y: Any = new CanThrow[Fail]() // error: illegal reference to erased class CanThrow
2626
val y2: Any = new CTF() // error: illegal reference to erased class CanThrow
27-
println(foo(true, ctf)) // error: ctf is declared as erased, but is in fact used
27+
println(foo(true, ctf)) // not error: ctf will be erased at erasure
2828
val a = (1, new CanThrow[Fail]()) // error: illegal reference to erased class CanThrow
2929
def b: (Int, CanThrow[Fail]) = ???
3030
def c = b._2 // ok; we only check creation sites

tests/run-custom-args/erased/erased-15.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scala.compiletime.ErasedFunction
1+
import scala.runtime.ErasedFunction
22

33
object Test {
44

0 commit comments

Comments
 (0)