Skip to content

Commit 08236ac

Browse files
committed
Various tests and test-fixes
1 parent 5479bd6 commit 08236ac

File tree

15 files changed

+81
-70
lines changed

15 files changed

+81
-70
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ object desugar {
18321832
cpy.ByNameTypeTree(parent)(annotate(tpnme.retainsByName, restpt))
18331833
case _ =>
18341834
annotate(tpnme.retains, parent)
1835-
case f: FunctionWithMods if f.erasedParams.contains(true) => makeFunctionWithValDefs(f, pt)
1835+
case f: FunctionWithMods if f.hasErasedParams => makeFunctionWithValDefs(f, pt)
18361836
}
18371837
desugared.withSpan(tree.span)
18381838
}

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

+2
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/TypeComparer.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -2118,9 +2118,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21182118
formals2.isEmpty
21192119
}
21202120
// Check if methods are erased, then the erased parameters match
2121-
val erasedValid = if tp1.hasErasedParams && tp2.hasErasedParams then
2122-
tp1.erasedParams == tp2.erasedParams
2123-
else !tp1.hasErasedParams && !tp2.hasErasedParams
2121+
val erasedValid =
2122+
if tp1.hasErasedParams && tp2.hasErasedParams then
2123+
tp1.erasedParams == tp2.erasedParams
2124+
else !tp1.hasErasedParams && !tp2.hasErasedParams
21242125

21252126
erasedValid && loop(tp1.paramInfos, tp2.paramInfos)
21262127
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,11 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
647647
case tp: MethodType =>
648648
def paramErasure(tpToErase: Type) =
649649
erasureFn(sourceLanguage, semiEraseVCs, isConstructor, isSymbol, wildcardOK)(tpToErase)
650-
val (names, formals0) = if (tp.hasErasedParams)
650+
val (names, formals0) = if tp.hasErasedParams then
651651
tp.paramNames
652652
.zip(tp.paramInfos)
653653
.zip(tp.erasedParams)
654-
.flatMap((p, e) => if e then None else Some(p))
654+
.collect{ case (param, isErased) if !isErased => param }
655655
.unzip
656656
else (tp.paramNames, tp.paramInfos)
657657
val formals = formals0.mapConserve(paramErasure)

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1851,8 +1851,7 @@ object Types {
18511851
val funType = defn.FunctionOf(
18521852
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
18531853
result1, isContextual, erasedParams)
1854-
if alwaysDependent || mt.isResultDependent then
1855-
RefinedType(funType, nme.apply, mt)
1854+
if alwaysDependent || mt.isResultDependent then RefinedType(funType, nme.apply, mt)
18561855
else funType
18571856
}
18581857

@@ -3702,7 +3701,7 @@ object Types {
37023701
val params = if (hasErasedParams)
37033702
tp.paramInfos
37043703
.zip(tp.erasedParams)
3705-
.flatMap((p, e) => if e then None else Some(p))
3704+
.collect { case (param, isErased) if !isErased => param }
37063705
else tp.paramInfos
37073706
resultSignature.prependTermParams(params, sourceLanguage)
37083707
case tp: PolyType =>
@@ -4053,7 +4052,7 @@ object Types {
40534052
}
40544053

40554054
object MethodType extends MethodTypeCompanion("MethodType") {
4056-
def companion(isContextual: Boolean = false, isImplicit: Boolean = false, erasedParams: List[Boolean] = List()): MethodTypeCompanion =
4055+
def companion(isContextual: Boolean = false, isImplicit: Boolean = false, erasedParams: List[Boolean] = Nil): MethodTypeCompanion =
40574056
val hasErased = erasedParams.contains(true)
40584057
if (isContextual)
40594058
if (hasErased) ErasedContextualMethodType(erasedParams) else ContextualMethodType

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

-1
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

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
290290
}
291291
"[applied to ("
292292
~ keywordText("using ").provided(tp.isContextualMethod)
293-
~ keywordText("erased ").provided(tp.isErasedMethod)
294293
~ argsText
295294
~ ") returning "
296295
~ toText(resultType)

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
27682768
def SomeModule: Symbol = dotc.core.Symbols.defn.SomeClass.companionModule
27692769
def ProductClass: Symbol = dotc.core.Symbols.defn.ProductClass
27702770
def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol =
2771-
if isErased
2772-
then dotc.core.Symbols.defn.ErasedFunctionClass
2771+
if isErased then dotc.core.Symbols.defn.ErasedFunctionClass
27732772
else dotc.core.Symbols.defn.FunctionSymbol(arity, isImplicit)
27742773
def TupleClass(arity: Int): Symbol =
27752774
dotc.core.Symbols.defn.TupleType(arity).nn.classSymbol.asClass

tests/neg/safeThrowsStrawman2.scala

+1-1
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
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
block
2-
x
32
foo
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
x
21
foo
3-
x
42
bar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
erased class Erased() {
3+
println("Oh no!!!")
4+
}
5+
6+
def f(x: Erased, y: Int = 0): Int = y + 5
7+
8+
def g() = Erased()
9+
10+
def main(args: Array[String]) =
11+
val y = Erased()
12+
val z = 10
13+
println(f(Erased()) + z + f(g(), 7))
14+
}

tests/run-custom-args/run-macros-erased/macro-erased/1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ object Macro {
1313
def case1(erased i: Expr[Int])(using Quotes): Expr[Int] = '{ 0 }
1414
def case2 (i: Int)(erased j: Expr[Int])(using Quotes): Expr[Int] = '{ 0 }
1515
def case3(erased i: Expr[Int]) (j: Int)(using Quotes): Expr[Int] = '{ 0 }
16-
def case4 (h: Int)(erased i: Expr[Int], j: Expr[Int])(using Quotes): Expr[Int] = '{ 0 }
17-
def case5(erased i: Expr[Int], j: Expr[Int]) (h: Int)(using Quotes): Expr[Int] = '{ 0 }
16+
def case4 (h: Int)(erased i: Expr[Int], erased j: Expr[Int])(using Quotes): Expr[Int] = '{ 0 }
17+
def case5(erased i: Expr[Int], erased j: Expr[Int]) (h: Int)(using Quotes): Expr[Int] = '{ 0 }
1818
def case6 (h: Int)(erased i: Expr[Int])(erased j: Expr[Int])(using Quotes): Expr[Int] = '{ 0 }
1919
def case7(erased i: Expr[Int]) (h: Int)(erased j: Expr[Int])(using Quotes): Expr[Int] = '{ 0 }
2020
def case8(erased i: Expr[Int])(erased j: Expr[Int]) (h: Int)(using Quotes): Expr[Int] = '{ 0 }

tests/run-macros/tasty-definitions-1.check

+50-50
Original file line numberDiff line numberDiff line change
@@ -82,56 +82,56 @@ ContextFunction22
8282
ContextFunction23
8383
ContextFunction24
8484
ContextFunction25
85-
ErasedFunction1
86-
ErasedFunction2
87-
ErasedFunction3
88-
ErasedFunction4
89-
ErasedFunction5
90-
ErasedFunction6
91-
ErasedFunction7
92-
ErasedFunction8
93-
ErasedFunction9
94-
ErasedFunction10
95-
ErasedFunction11
96-
ErasedFunction12
97-
ErasedFunction13
98-
ErasedFunction14
99-
ErasedFunction15
100-
ErasedFunction16
101-
ErasedFunction17
102-
ErasedFunction18
103-
ErasedFunction19
104-
ErasedFunction20
105-
ErasedFunction21
106-
ErasedFunction22
107-
ErasedFunction23
108-
ErasedFunction24
109-
ErasedFunction25
110-
ErasedContextFunction1
111-
ErasedContextFunction2
112-
ErasedContextFunction3
113-
ErasedContextFunction4
114-
ErasedContextFunction5
115-
ErasedContextFunction6
116-
ErasedContextFunction7
117-
ErasedContextFunction8
118-
ErasedContextFunction9
119-
ErasedContextFunction10
120-
ErasedContextFunction11
121-
ErasedContextFunction12
122-
ErasedContextFunction13
123-
ErasedContextFunction14
124-
ErasedContextFunction15
125-
ErasedContextFunction16
126-
ErasedContextFunction17
127-
ErasedContextFunction18
128-
ErasedContextFunction19
129-
ErasedContextFunction20
130-
ErasedContextFunction21
131-
ErasedContextFunction22
132-
ErasedContextFunction23
133-
ErasedContextFunction24
134-
ErasedContextFunction25
85+
ErasedFunction
86+
ErasedFunction
87+
ErasedFunction
88+
ErasedFunction
89+
ErasedFunction
90+
ErasedFunction
91+
ErasedFunction
92+
ErasedFunction
93+
ErasedFunction
94+
ErasedFunction
95+
ErasedFunction
96+
ErasedFunction
97+
ErasedFunction
98+
ErasedFunction
99+
ErasedFunction
100+
ErasedFunction
101+
ErasedFunction
102+
ErasedFunction
103+
ErasedFunction
104+
ErasedFunction
105+
ErasedFunction
106+
ErasedFunction
107+
ErasedFunction
108+
ErasedFunction
109+
ErasedFunction
110+
ErasedFunction
111+
ErasedFunction
112+
ErasedFunction
113+
ErasedFunction
114+
ErasedFunction
115+
ErasedFunction
116+
ErasedFunction
117+
ErasedFunction
118+
ErasedFunction
119+
ErasedFunction
120+
ErasedFunction
121+
ErasedFunction
122+
ErasedFunction
123+
ErasedFunction
124+
ErasedFunction
125+
ErasedFunction
126+
ErasedFunction
127+
ErasedFunction
128+
ErasedFunction
129+
ErasedFunction
130+
ErasedFunction
131+
ErasedFunction
132+
ErasedFunction
133+
ErasedFunction
134+
ErasedFunction
135135
Tuple2
136136
Tuple3
137137
Tuple4

0 commit comments

Comments
 (0)