Skip to content

Commit 926e6a3

Browse files
authored
Do not flag match types as Deferred and amend #20077 (#20147)
Match types are already not flagged as `Deferred` when unpickled. This caused varying results for `ImplicitRunInfo#isAnchor`, by not reaching the `isMatchAlias` condition when created from the Namer. Ensures both #20071 and #20136 each have the same result, when compiled with a classpath dependency as when merged into a single file. Fixes #20136
2 parents 2b09680 + c794eab commit 926e6a3

File tree

9 files changed

+55
-6
lines changed

9 files changed

+55
-6
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1544,8 +1544,6 @@ class TreeUnpickler(reader: TastyReader,
15441544
// as the reduction of the match type definition!
15451545
//
15461546
// We also override the type, as that's what Typer does.
1547-
// The difference here is that a match type that reduces to a non-match type
1548-
// makes the TypeRef for that definition will have a TypeAlias info instead of a MatchAlias.
15491547
tpt.overwriteType(tpt.tpe.normalized)
15501548
tpt
15511549
case TYPEBOUNDStpt =>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ trait ImplicitRunInfo:
636636
else if implicitScopeCache.contains(t) then parts += t
637637
else
638638
partSeen += t
639-
t.dealias.normalized match
639+
t.dealias match
640640
case t: TypeRef =>
641641
if isAnchor(t.symbol) then
642642
parts += t
@@ -817,7 +817,7 @@ trait ImplicitRunInfo:
817817
else AndType.make(apply(lo), apply(hi))
818818
case u => apply(u)
819819

820-
def apply(t: Type) = t.dealias match
820+
def apply(t: Type) = t.dealias.normalized match
821821
case t: TypeRef =>
822822
if t.symbol.isClass || isAnchor(t.symbol) then t else applyToUnderlying(t)
823823
case t: TypeVar => apply(t.underlying)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ class Namer { typer: Typer =>
268268
else if flags.isAllOf(EnumValue) && ctx.owner.isStaticOwner then flags |= JavaStatic
269269
case tree: TypeDef =>
270270
def analyzeRHS(rhs: Tree): Unit = rhs match
271-
case _: TypeBoundsTree | _: MatchTypeTree =>
272-
flags |= Deferred // Typedefs with Match rhs classify as abstract
271+
case _: TypeBoundsTree =>
272+
flags |= Deferred
273273
case LambdaTypeTree(_, body) =>
274274
analyzeRHS(body)
275275
case _ =>
File renamed without changes.

tests/neg/i20071b/A_1.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 = ???

tests/neg/i20071b/B_2.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
def test: Unit =
3+
foo[Scope] // ok
4+
bar[Scope] // error
5+
6+
import Scope.i
7+
bar[Scope] // ok
8+

tests/pos/i20136a.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
trait Expr:
3+
type Value
4+
object Expr:
5+
type Of[V] = Expr { type Value = V }
6+
type ExtractValue[E <: Expr] = E match
7+
case Expr.Of[v] => v
8+
9+
trait TC[E <: Expr]:
10+
type Elem = Expr.ExtractValue[E]
11+
class BIExpr extends Expr:
12+
type Value = BigInt
13+
class Foo extends TC[BIExpr]:
14+
val v: Elem = 0

tests/pos/i20136b/A_1.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package a
2+
3+
trait Expr:
4+
type Value
5+
object Expr:
6+
type Of[V] = Expr { type Value = V }
7+
type ExtractValue[E <: Expr] = E match
8+
case Expr.Of[v] => v

tests/pos/i20136b/B_2.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package a
2+
3+
trait TC[E <: Expr]:
4+
type Elem = Expr.ExtractValue[E]
5+
class BIExpr extends Expr:
6+
type Value = BigInt
7+
class Foo extends TC[BIExpr]:
8+
val v: Elem = 0

0 commit comments

Comments
 (0)