Skip to content

Commit 37fa3c6

Browse files
committed
Make match type aliases anchors
1 parent 1dd04dd commit 37fa3c6

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,14 @@ trait ImplicitRunInfo:
485485
if migrateTo3 then false else sym.is(Package) || sym.isPackageObject
486486

487487
/** Is `sym` an anchor type for which givens may exist? Anchor types are classes,
488-
* opaque type aliases, and abstract types, but not type parameters or package objects.
488+
* opaque type aliases, match aliases and abstract types, but not type parameters
489+
* or package objects.
489490
*/
490491
private def isAnchor(sym: Symbol) =
491492
sym.isClass && !isExcluded(sym)
492493
|| sym.isOpaqueAlias
493494
|| sym.is(Deferred, butNot = Param)
495+
|| sym.info.isInstanceOf[MatchAlias]
494496

495497
private def computeIScope(rootTp: Type): OfTypeImplicits =
496498

@@ -618,8 +620,8 @@ trait ImplicitRunInfo:
618620
/** The implicit scope of a type `tp`, which is specified by the following definitions.
619621
*
620622
* A reference is an _anchor_ if it refers to an object, a class, a trait, an
621-
* abstract type, or an opaque type alias. References to packages and package
622-
* objects are anchors only under -source:3.0-migration.
623+
* abstract type, an opaque type alias, or a match type alias. References to
624+
* packages and package objects are anchors only under -source:3.0-migration.
623625
*
624626
* The _anchors_ of a type `T` is a set of references defined as follows:
625627
*
@@ -642,9 +644,10 @@ trait ImplicitRunInfo:
642644
* - If `T` is a reference to an opaque type alias named `A`, S includes
643645
* a reference to an object `A` defined in the same scope as the type, if it exists,
644646
* as well as the implicit scope of `T`'s underlying type or bounds.
645-
* - If `T` is a reference to an an abstract type named `A`, S includes
646-
* a reference to an object `A` defined in the same scope as the type, if it exists,
647-
* as well as the implicit scopes of `T`'s lower and upper bound.
647+
* - If `T` is a reference to an an abstract type or match type alias named `A`,
648+
* S includes a reference to an object `A` defined in the same scope as the type,
649+
* if it exists, as well as the implicit scopes of `T`'s lower and upper bound,
650+
* if present.
648651
* - If `T` is a reference to an anchor of the form `p.A` then S also includes
649652
* all term references on the path `p`.
650653
* - If `T` is some other type, S includes the implicit scopes of all anchors of `T`.

docs/docs/reference/changed-features/implicit-resolution.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ have only `b` in its implicit search scope but not `a`.
5555
In more detail, here are the rules for what constitutes the implicit scope of
5656
a type:
5757

58-
**Definition:** A reference is an _anchor_ if it refers to an object, a class, a trait, an abstract type, or an opaque type alias. References to packages and package objects are anchors only under -source:3.0-migration.
58+
**Definition:** A reference is an _anchor_ if it refers to an object, a class, a trait, an abstract type, an opaque type alias, or a match type alias. References to packages and package objects are anchors only under -source:3.0-migration.
5959

6060
**Definition:** The _anchors_ of a type _T_ is a set of references defined as follows:
6161

@@ -76,9 +76,8 @@ a type:
7676
- If _T_ is a reference to an opaque type alias named _A_, _S_ includes
7777
a reference to an object _A_ defined in the same scope as the type, if it exists,
7878
as well as the implicit scope of _T_'s underlying type or bounds.
79-
- If _T_ is a reference to an an abstract type named _A_, _S_ includes
80-
a reference to an object _A_ defined in the same scope as the type, if it exists,
81-
as well as the implicit scopes of _T_'s lower and upper bound.
79+
- If _T_ is a reference to an an abstract type or match type alias
80+
named _A_, _S_ includes a reference to an object _A_ defined in the same scope as the type, if it exists, as well as the implicit scopes of _T_'s lower and upper bound, if present.
8281
- If _T_ is a reference to an anchor of the form _p.A_ then _S_ also includes
8382
all term references on the path _p_.
8483
- If _T_ is some other type, _S_ includes the implicit scopes of all anchors of _T_.

0 commit comments

Comments
 (0)