File tree Expand file tree Collapse file tree 4 files changed +40
-4
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 4 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -976,10 +976,23 @@ trait Implicits:
976976 then return NoMatchingImplicitsFailure
977977
978978 val result0 =
979- try ImplicitSearch (pt, argument, span).bestImplicit
979+ // If we are searching implicits when resolving an import symbol, start the search
980+ // in the first enclosing context that does not have the same scope and owner as the current
981+ // context. Without that precaution, an eligible implicit in the current scope
982+ // would cause a cyclic reference error (if the import is named) or cause a
983+ // spurious import skip (if the import is a wildcard import). See i12802 for a test case.
984+ var searchCtx = ctx
985+ if ctx.owner.isImport then
986+ while
987+ searchCtx = searchCtx.outer
988+ (searchCtx.scope eq ctx.scope) && (searchCtx.owner eq ctx.owner.owner)
989+ do ()
990+
991+ try ImplicitSearch (pt, argument, span)(using searchCtx).bestImplicit
980992 catch case ce : CyclicReference =>
981993 ce.inImplicitSearch = true
982994 throw ce
995+ end result0
983996
984997 val result =
985998 result0 match {
Original file line number Diff line number Diff line change 1+ trait M :
2+ type X
3+ object X :
4+ def foo (): X = ???
5+
6+ transparent inline def m (using m : M ): m.type = m
7+
8+ def Test1 =
9+ given M = new M {}
10+ import m .* // error: no implicit argument of type M was found
11+ val x : X = X .foo()
12+ println(x)
Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ def doSomething(body: M ?=> Unit) = body(using new M{})
1010
1111def Test1 =
1212 given M = new M {}
13- import m .*
14- val x : X = X .foo()
15- println(x)
13+ locally {
14+ import m .*
15+ val x : X = X .foo()
16+ println(x)
17+ }
1618
1719def Test2 =
1820
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+
3+ object Boo :
4+ def foo (using Quotes ): Unit =
5+ import quotes .reflect ._
6+ given Option [Symbol ] = Some [Symbol ](??? )
7+ def bar (using Quotes ): Unit =
8+ import quotes .reflect .Symbol
9+ given Option [Symbol ] = Some [Symbol ](??? )
You can’t perform that action at this time.
0 commit comments