From 71fb5ad03dc3704038565df7920e667d018d692c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 26 May 2021 18:35:19 +0200 Subject: [PATCH] Typecheck imports with import symbol as owner Fixes #12606 This broke before since the inliner is not prepared to operate with a class as owner. --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/neg/i12606.scala | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i12606.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index f421c75f9287..7893114b86d9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -703,7 +703,7 @@ class Namer { typer: Typer => typer1.defDefSig(original, sym)(using localContext(sym).setTyper(typer1)) case imp: Import => try - val expr1 = typedImportQualifier(imp, typedAheadExpr) + val expr1 = typedImportQualifier(imp, typedAheadExpr(_, _)(using ctx.withOwner(sym))) ImportType(expr1) catch case ex: CyclicReference => typr.println(s"error while completing ${imp.expr}") diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index cda1daafd252..184dfac6537b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2450,7 +2450,7 @@ class Typer extends Namer else typd(imp.expr, AnySelectionProto) def typedImport(imp: untpd.Import, sym: Symbol)(using Context): Import = - val expr1 = typedImportQualifier(imp, typedExpr) + val expr1 = typedImportQualifier(imp, typedExpr(_, _)(using ctx.withOwner(sym))) checkLegalImportPath(expr1) val selectors1 = typedSelectors(imp.selectors) assignType(cpy.Import(imp)(expr1, selectors1), sym) diff --git a/tests/neg/i12606.scala b/tests/neg/i12606.scala new file mode 100644 index 000000000000..53f88387af36 --- /dev/null +++ b/tests/neg/i12606.scala @@ -0,0 +1,8 @@ +import scala.quoted._ + +trait ReflectModule { + implicit def q: Quotes + import quotes.reflect._ // error + + def foo(x: TypeRepr): Unit = ??? +} \ No newline at end of file