File tree 3 files changed +31
-2
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -636,7 +636,7 @@ trait ImplicitRunInfo:
636
636
else if implicitScopeCache.contains(t) then parts += t
637
637
else
638
638
partSeen += t
639
- t.dealias match
639
+ t.dealias.normalized match
640
640
case t : TypeRef =>
641
641
if isAnchor(t.symbol) then
642
642
parts += t
@@ -663,7 +663,6 @@ trait ImplicitRunInfo:
663
663
traverseChildren(t)
664
664
case t =>
665
665
traverseChildren(t)
666
- traverse(t.normalized)
667
666
catch case ex : Throwable => handleRecursive(" collectParts of" , t.show, ex)
668
667
669
668
def apply (tp : Type ): collection.Set [Type ] =
@@ -775,6 +774,7 @@ trait ImplicitRunInfo:
775
774
* if `T` is of the form `(P#x).type`, the anchors of `P`.
776
775
* - If `T` is the this-type of a static object, the anchors of a term reference to that object.
777
776
* - If `T` is some other this-type `P.this.type`, the anchors of `P`.
777
+ * - If `T` is match type or an applied match alias, the anchors of the normalization of `T`.
778
778
* - If `T` is some other type, the union of the anchors of each constituent type of `T`.
779
779
*
780
780
* The _implicit scope_ of a type `tp` is the smallest set S of term references (i.e. TermRefs)
Original file line number Diff line number Diff line change
1
+
2
+ trait Scope
3
+ object Scope :
4
+ given i : Int = ???
5
+
6
+ type ReferencesScope [S ] >: Int <: Int
7
+
8
+ type ScopeToInt [Why ] = Why match
9
+ case Scope => Int
10
+
11
+ def foo [T ](using d : ReferencesScope [T ]): Any = ???
12
+
13
+ def bar [T ](using d : ScopeToInt [T ]): Any = ???
14
+
15
+ def test : Unit =
16
+ foo[Scope ] // ok
17
+ bar[Scope ] // error
18
+
19
+ /*
20
+ Before the changes:
21
+ `ScopeToInt[Scope]` may or may not be reduced before implicit search,
22
+ thereby impacting the scope considered for the search. `Scope.i` is included
23
+ iff `Scope` still appears in the type, which is the case only before reduction.
24
+ In contrast, `ReferencesScope[Scope]` is ok since it will never lose the anchor.
25
+ */
Original file line number Diff line number Diff line change 1
1
// Fails in each cases below
2
+ import Decoder .{derived as _ , given }
3
+ // NOTE Decoder.derived is already in the implicit scope
4
+ // but the others require an import as they depend on match type reduction
5
+
2
6
enum Env derives Decoder :
3
7
case Local ,Sit ,Prod
4
8
You can’t perform that action at this time.
0 commit comments