Skip to content

Fix isMatch #12206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ object SymDenotations {
TypeBounds.empty

info match
case TypeAlias(alias) if isOpaqueAlias && owner.isClass =>
setAlias(alias)
case info: AliasingBounds if isOpaqueAlias && owner.isClass =>
setAlias(info.alias)
HKTypeLambda.boundsFromParams(tparams, bounds(rhs))
case _ =>
info
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ object TypeOps:
sym.is(Package) || sym.isStatic && isStaticPrefix(pre.prefix)
case _ => true

def apply(tp: Type): Type = tp match {
def apply(tp: Type): Type = tp match
case tp: TermRef
if toAvoid(tp.symbol) || partsToAvoid(Nil, tp.info).nonEmpty =>
tp.info.widenExpr.dealias match {
Expand Down Expand Up @@ -459,7 +459,7 @@ object TypeOps:
mapOver(tl)
case _ =>
mapOver(tp)
}
end apply

/** Three deviations from standard derivedSelect:
* 1. We first try a widening conversion to the type's info with
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ object Types {
def isMatch(using Context): Boolean = stripped match {
case _: MatchType => true
case tp: HKTypeLambda => tp.resType.isMatch
case tp: AppliedType =>
tp.tycon match
case tycon: TypeRef => tycon.info.isInstanceOf[MatchAlias]
case _ => false
case _ => false
}

Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ typeclass-derivation2d.scala
typeclass-derivation3.scala
varargs-abstract
zero-arity-case-class.scala
i12194.scala
24 changes: 24 additions & 0 deletions tests/pos/i12178.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
opaque type LabelTagged[TLabel <: Singleton & String, TValue] = TValue

object LabelTagged:
def apply[TLabel <: Singleton & String, TValue]
(
label: TLabel,
value: TValue,
)
: LabelTagged[TLabel, TValue] = value

extension[TLabel <: Singleton & String, TValue] (labelTagged: LabelTagged[TLabel, TValue])
def value
: TValue = labelTagged

def label
(using label: ValueOf[TLabel])
: TLabel
= label.value

@main def hello(): Unit = {
val foo: LabelTagged["foo", Int] = LabelTagged("foo", 10)
println(label(foo)) // OK
//println(foo.label) // not OK
}
3 changes: 3 additions & 0 deletions tests/pos/i12194-opaque.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opaque type ProductK[F[_], T <: Tuple] = Tuple.Map[T, F]
object ProductK:
def of[F[_], T <: Tuple](t: Tuple.Map[T, F]): ProductK[F, T] = t
1 change: 1 addition & 0 deletions tests/run/i12194.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
List(foo, bar)
16 changes: 16 additions & 0 deletions tests/run/i12194.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import scala.annotation.implicitNotFound
import scala.compiletime.package$package.summonAll
import scala.util.Try
import scala.util.Success
import scala.util.Failure
import scala.util.NotGiven
import scala.deriving.*

def f(): Unit =
var t = (??? : Tuple1[ValueOf["foo"]]); t.toList.map(identity)
(??? : Tuple1[ValueOf["foo"]]).toList.map(identity)

@main def Test(): Unit =
println(summonAll[Tuple.Map[("foo", "bar"), ValueOf]].toList.map{
case str: ValueOf[_] ⇒ str.value
})