Skip to content
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

Run all MatchType reduction under Mode.Type #17937

Merged
merged 1 commit into from
Jun 23, 2023
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/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4943,7 +4943,7 @@ object Types {
record("MatchType.reduce computed")
if (myReduced != null) record("MatchType.reduce cache miss")
myReduced =
trace(i"reduce match type $this $hashCode", matchTypes, show = true) {
trace(i"reduce match type $this $hashCode", matchTypes, show = true)(inMode(Mode.Type) {
def matchCases(cmp: TrackingTypeComparer): Type =
val saved = ctx.typerState.snapshot()
try cmp.matchCases(scrutinee.normalized, cases)
Expand All @@ -4956,7 +4956,7 @@ object Types {
// instantiations during matchtype reduction

TypeComparer.tracked(matchCases)
}
})
myReduced.nn
}

Expand Down
26 changes: 26 additions & 0 deletions tests/pos/i16408.min1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
object Helpers:
type NodeFun[R] = Matchable // compiles without [R] parameter

type URIFun[R] = R match
case GetURI[u] => u & NodeFun[R]

private type GetURI[U] = RDF { type URI = U }
end Helpers

trait RDF:
type URI

trait ROps[R <: RDF]:
def auth(uri: Helpers.URIFun[R]): String

object TraitRDF extends RDF:
override type URI = TraitTypes.UriImpl

val rops = new ROps[TraitRDF.type] {
override def auth(uri: Helpers.URIFun[TraitRDF.type]): String = ???
}
end TraitRDF

object TraitTypes:
trait UriImpl // doesn't compile
// class UriImpl // compiles
22 changes: 22 additions & 0 deletions tests/pos/i16408.min2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
object Helpers:
type NodeFun[R] = Matchable // compiles without [R] parameter

type URIFun[R] = R match
case RDF[u] => u & NodeFun[R]
end Helpers

trait RDF[URIParam]

trait ROps[R <: RDF[?]]:
def auth(uri: Helpers.URIFun[R]): String

object TraitRDF extends RDF[TraitTypes.UriImpl]:

val rops = new ROps[TraitRDF.type] {
override def auth(uri: Helpers.URIFun[TraitRDF.type]): String = ???
}
end TraitRDF

object TraitTypes:
trait UriImpl // doesn't compile
// class UriImpl // compiles
57 changes: 57 additions & 0 deletions tests/pos/i16408.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import scala.util.Try

trait RDF:
rdf =>

type R = rdf.type
type Node <: Matchable
type URI <: Node

given rops: ROps[R]
end RDF

object RDF:
type Node[R <: RDF] = R match
case GetNode[n] => Matchable //n & rNode[R]

type URI[R <: RDF] <: Node[R] = R match
case GetURI[u] => u & Node[R]

private type GetNode[N] = RDF { type Node = N }
private type GetURI[U] = RDF { type URI = U }
end RDF

trait ROps[R <: RDF]:
def mkUri(str: String): Try[RDF.URI[R]]
def auth(uri: RDF.URI[R]): Try[String]

object TraitTypes:
trait Node:
def value: String

trait Uri extends Node

def mkUri(u: String): Uri =
new Uri { def value = u }

object TraitRDF extends RDF:
import TraitTypes as tz

override opaque type Node <: Matchable = tz.Node
override opaque type URI <: Node = tz.Uri

given rops: ROps[R] with
override def mkUri(str: String): Try[RDF.URI[R]] = Try(tz.mkUri(str))
override def auth(uri: RDF.URI[R]): Try[String] =
Try(java.net.URI.create(uri.value).getAuthority())

end TraitRDF

class Test[R <: RDF](using rops: ROps[R]):
import rops.given
lazy val uriT: Try[RDF.URI[R]] = rops.mkUri("https://bblfish.net/#i")
lazy val x: String = "uri authority=" + uriT.map(u => rops.auth(u))

@main def run =
val test = Test[TraitRDF.type]
println(test.x)