Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't GLB binders of type patterns, use the type directly
In type patterns `c match { case x: T }`, the translation would assign the GLB of `c`'s type and `T` to the varaible `x`. This seems to trace back to the first version of the "virtual pattern matcher". I could not find a similar use of `glb` in that revision of the codebase. So I'm not sure if it was a new addition, or picked up from the previous implementation. https://github.com/scala/scala/blob/8a9fd64129926eea35f7dca181242855f14e153f/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala#L438-L440 In the test case, the GLB collapsed to `Null` because its computation failed (combination of f-bounds, existentials, skolems that I don't follow), see `throw GlbFailure`. This is how it's been for 14 years (b894f80). This resulted in a cast to `Null$` failing at runtime. I assume GLB is fixed in Scala 3, as this core of the type system has a new implementation. But the test case as such doesn't compile in Scala 3 due to the non-wildcard existential.
- Loading branch information
Showing
4 changed files
with
50 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
warning: 1 feature warning; re-run with -feature for details | ||
IOS |
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,17 @@ | ||
object Test { | ||
trait MFSS[X <: MFSS[_]] | ||
trait CS extends MFSS[CS] | ||
trait MFI { type ST } | ||
case class MFSD[S](mFI: MFI {type ST = S}) | ||
case object IOS extends MFI { type ST = CS } | ||
type SD = MFSD[S] forSome { | ||
type S <: MFSS[S] | ||
} | ||
def bad(sd: SD) = sd.mFI match { | ||
case ios: IOS.type => println(ios) | ||
} | ||
def main(args: Array[String]): Unit = { | ||
val x = MFSD(IOS) | ||
bad(x) | ||
} | ||
} |
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