-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13292 from dotty-staging/fix-merge-constraint-3
Reimplement constraint merging for correctness
- Loading branch information
Showing
11 changed files
with
185 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dotty.tools | ||
package dotc.core | ||
|
||
import vulpix.TestConfiguration | ||
|
||
import dotty.tools.dotc.core.Contexts.{*, given} | ||
import dotty.tools.dotc.core.Decorators.{*, given} | ||
import dotty.tools.dotc.core.Symbols.* | ||
import dotty.tools.dotc.core.Types.* | ||
import dotty.tools.dotc.typer.ProtoTypes.constrained | ||
|
||
import org.junit.Test | ||
|
||
import dotty.tools.DottyTest | ||
|
||
class ConstraintsTest: | ||
|
||
@Test def mergeParamsTransitivity: Unit = | ||
inCompilerContext(TestConfiguration.basicClasspath, | ||
scalaSources = "trait A { def foo[S, T, R]: Any }") { | ||
val tp = constrained(requiredClass("A").typeRef.select("foo".toTermName).info.asInstanceOf[TypeLambda]) | ||
val List(s, t, r) = tp.paramRefs | ||
|
||
val innerCtx = ctx.fresh.setExploreTyperState() | ||
inContext(innerCtx) { | ||
s <:< t | ||
} | ||
|
||
t <:< r | ||
|
||
ctx.typerState.mergeConstraintWith(innerCtx.typerState) | ||
assert(s frozen_<:< r, | ||
i"Merging constraints `?S <: ?T` and `?T <: ?R` should result in `?S <:< ?R`: ${ctx.typerState.constraint}") | ||
} | ||
end mergeParamsTransitivity | ||
|
||
@Test def mergeBoundsTransitivity: Unit = | ||
inCompilerContext(TestConfiguration.basicClasspath, | ||
scalaSources = "trait A { def foo[S, T]: Any }") { | ||
val tp = constrained(requiredClass("A").typeRef.select("foo".toTermName).info.asInstanceOf[TypeLambda]) | ||
val List(s, t) = tp.paramRefs | ||
|
||
val innerCtx = ctx.fresh.setExploreTyperState() | ||
inContext(innerCtx) { | ||
s <:< t | ||
} | ||
|
||
defn.IntType <:< s | ||
|
||
ctx.typerState.mergeConstraintWith(innerCtx.typerState) | ||
assert(defn.IntType frozen_<:< t, | ||
i"Merging constraints `?S <: ?T` and `Int <: ?S` should result in `Int <:< ?T`: ${ctx.typerState.constraint}") | ||
} | ||
end mergeBoundsTransitivity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class ComponentSimple | ||
|
||
class Props { | ||
def apply(props: Any): Any = ??? | ||
} | ||
|
||
class Foo[C] { | ||
def build: ComponentSimple = ??? | ||
} | ||
|
||
class Bar[E] { | ||
def render(r: E => Any): Unit = {} | ||
} | ||
|
||
trait Conv[A, B] { | ||
def apply(a: A): B | ||
} | ||
|
||
object Test { | ||
def toComponentCtor[F](c: ComponentSimple): Props = ??? | ||
|
||
def defaultToNoBackend[G, H](ev: G => Foo[H]): Conv[Foo[H], Bar[H]] = ??? | ||
|
||
def conforms[A]: A => A = ??? | ||
|
||
def problem = Main // crashes | ||
|
||
def foo[H]: Foo[H] = ??? | ||
|
||
val NameChanger = | ||
foo | ||
.build | ||
|
||
val Main = | ||
defaultToNoBackend(conforms).apply(foo) | ||
.render(_ => toComponentCtor(NameChanger)(13)) | ||
} |