forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce some match type in inlining to avoid opaque type headaches
The inliner tries to handle opaque types by replacing prefixes containing them by proxy objects with type aliases. When the type we're mapping is a match type application, this can end up breaking its reduction. Reducing match type applications instead of performing this mapping seems to avoid the issue in practice, but I don't know if it completely solves the problem. Fixes scala#20427.
- Loading branch information
Showing
4 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import scala.language.experimental.namedTuples | ||
|
||
object Test: | ||
type NT = NamedTuple.Concat[(hi: Int), (bla: String)] | ||
def foo(x: NT) = | ||
x.hi // error |
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,19 @@ | ||
object Foo: | ||
opaque type Wrapper[T] = T | ||
def part[T](w: Wrapper[T]): T = w | ||
inline def part2[T](w: Wrapper[T]): T = part(w) //part(w.asInstanceOf[Wrapper[T]]) also fixes the issue | ||
type Rewrap[W] = Wrapper[Extra.Unwrap[W]] | ||
|
||
object Extra: | ||
type Unwrap[W] = W match | ||
case Foo.Wrapper[t] => t | ||
type Rewrap[W] = Foo.Wrapper[Unwrap[W]] | ||
|
||
object Test: | ||
type X = Extra.Rewrap[Foo.Wrapper[Int]] | ||
def foo1(x: Foo.Wrapper[Extra.Unwrap[Foo.Wrapper[Int]]]) = | ||
Foo.part(x) // ok | ||
Foo.part2(x) // ok | ||
def foo2(x: X) = | ||
Foo.part(x) // ok | ||
Foo.part2(x) // error |