Skip to content

Commit bf815cf

Browse files
committed
Fix #4350: Do not check prefix of class type parameters
1 parent 8feb596 commit bf815cf

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
245245
l == level ||
246246
sym.is(Inline) && sym.owner.is(Macro) && sym.info.isValueType && l - 1 == level
247247
case None =>
248-
true
248+
level == 0
249249
}
250250

251251
/** Issue a "splice outside quote" error unless we ar in the body of an inline method */
@@ -289,7 +289,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
289289
if (!isThis) sym.show
290290
else if (sym.is(ModuleClass)) sym.sourceModule.show
291291
else i"${sym.name}.this"
292-
if (!isThis && sym.maybeOwner.isType)
292+
if (!isThis && sym.maybeOwner.isType && !sym.is(Param))
293293
check(sym.owner, sym.owner.thisType, pos)
294294
else if (sym.exists && !sym.isStaticOwner && !levelOK(sym))
295295
for (errMsg <- tryHeal(tp, pos))

tests/neg/i4350.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted.Type
2+
3+
class Foo[T] {
4+
'(null.asInstanceOf[T]) // error
5+
}

tests/pos/i4350.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted.Type
2+
3+
class Foo[T: Type] {
4+
'(null.asInstanceOf[T])
5+
}

tests/run-with-compiler/i4350.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
null.asInstanceOf[Object]
3+
}
4+
{
5+
null.asInstanceOf[String]
6+
}

tests/run-with-compiler/i4350.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import dotty.tools.dotc.quoted.Toolbox._
2+
3+
import scala.quoted.Type
4+
5+
class Foo[T: Type] {
6+
def q = '(null.asInstanceOf[T])
7+
}
8+
9+
object Test {
10+
def main(args: Array[String]): Unit = {
11+
println((new Foo[Object]).q.show)
12+
println((new Foo[String]).q.show)
13+
}
14+
}

0 commit comments

Comments
 (0)