Skip to content

Commit 311dc17

Browse files
authored
Merge pull request #12206 from dotty-staging/fix-i12194
Fix isMatch
2 parents 9e0dc21 + c8d9a00 commit 311dc17

File tree

8 files changed

+53
-4
lines changed

8 files changed

+53
-4
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ object SymDenotations {
432432
TypeBounds.empty
433433

434434
info match
435-
case TypeAlias(alias) if isOpaqueAlias && owner.isClass =>
436-
setAlias(alias)
435+
case info: AliasingBounds if isOpaqueAlias && owner.isClass =>
436+
setAlias(info.alias)
437437
HKTypeLambda.boundsFromParams(tparams, bounds(rhs))
438438
case _ =>
439439
info

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ object TypeOps:
427427
sym.is(Package) || sym.isStatic && isStaticPrefix(pre.prefix)
428428
case _ => true
429429

430-
def apply(tp: Type): Type = tp match {
430+
def apply(tp: Type): Type = tp match
431431
case tp: TermRef
432432
if toAvoid(tp.symbol) || partsToAvoid(Nil, tp.info).nonEmpty =>
433433
tp.info.widenExpr.dealias match {
@@ -466,7 +466,7 @@ object TypeOps:
466466
mapOver(tl)
467467
case _ =>
468468
mapOver(tp)
469-
}
469+
end apply
470470

471471
/** Three deviations from standard derivedSelect:
472472
* 1. We first try a widening conversion to the type's info with

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ object Types {
423423
def isMatch(using Context): Boolean = stripped match {
424424
case _: MatchType => true
425425
case tp: HKTypeLambda => tp.resType.isMatch
426+
case tp: AppliedType =>
427+
tp.tycon match
428+
case tycon: TypeRef => tycon.info.isInstanceOf[MatchAlias]
429+
case _ => false
426430
case _ => false
427431
}
428432

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ typeclass-derivation2d.scala
3333
typeclass-derivation3.scala
3434
varargs-abstract
3535
zero-arity-case-class.scala
36+
i12194.scala

tests/pos/i12178.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
opaque type LabelTagged[TLabel <: Singleton & String, TValue] = TValue
2+
3+
object LabelTagged:
4+
def apply[TLabel <: Singleton & String, TValue]
5+
(
6+
label: TLabel,
7+
value: TValue,
8+
)
9+
: LabelTagged[TLabel, TValue] = value
10+
11+
extension[TLabel <: Singleton & String, TValue] (labelTagged: LabelTagged[TLabel, TValue])
12+
def value
13+
: TValue = labelTagged
14+
15+
def label
16+
(using label: ValueOf[TLabel])
17+
: TLabel
18+
= label.value
19+
20+
@main def hello(): Unit = {
21+
val foo: LabelTagged["foo", Int] = LabelTagged("foo", 10)
22+
println(label(foo)) // OK
23+
//println(foo.label) // not OK
24+
}

tests/pos/i12194-opaque.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
opaque type ProductK[F[_], T <: Tuple] = Tuple.Map[T, F]
2+
object ProductK:
3+
def of[F[_], T <: Tuple](t: Tuple.Map[T, F]): ProductK[F, T] = t

tests/run/i12194.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
List(foo, bar)

tests/run/i12194.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.annotation.implicitNotFound
2+
import scala.compiletime.package$package.summonAll
3+
import scala.util.Try
4+
import scala.util.Success
5+
import scala.util.Failure
6+
import scala.util.NotGiven
7+
import scala.deriving.*
8+
9+
def f(): Unit =
10+
var t = (??? : Tuple1[ValueOf["foo"]]); t.toList.map(identity)
11+
(??? : Tuple1[ValueOf["foo"]]).toList.map(identity)
12+
13+
@main def Test(): Unit =
14+
println(summonAll[Tuple.Map[("foo", "bar"), ValueOf]].toList.map{
15+
case str: ValueOf[_] str.value
16+
})

0 commit comments

Comments
 (0)