-
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 #8867 from dotty-staging/fix-#8861
Fix #8861: Avoid parameters when instantiating closure results
- Loading branch information
Showing
8 changed files
with
145 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
object Test { | ||
sealed trait Container { s => | ||
type A | ||
def visit[R](int: IntV & s.type => R, str: StrV & s.type => R): R | ||
} | ||
final class IntV extends Container { s => | ||
type A = Int | ||
val i: Int = 42 | ||
def visit[R](int: IntV & s.type => R, str: StrV & s.type => R): R = int(this) | ||
} | ||
final class StrV extends Container { s => | ||
type A = String | ||
val t: String = "hello" | ||
def visit[R](int: IntV & s.type => R, str: StrV & s.type => R): R = str(this) | ||
} | ||
|
||
def minimalOk[R](c: Container { type A = R }): R = c.visit[R]( | ||
int = vi => vi.i : vi.A, | ||
str = vs => vs.t : vs.A | ||
) | ||
def minimalFail[M](c: Container { type A = M }): M = c.visit( | ||
int = vi => vi.i : vi.A, | ||
str = vs => vs.t : vs.A // error | ||
) | ||
|
||
def main(args: Array[String]): Unit = { | ||
val e: Container { type A = String } = new StrV | ||
println(minimalOk(e)) // this one prints "hello" | ||
println(minimalFail(e)) // this one fails with ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer | ||
} | ||
} |
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,27 @@ | ||
trait S { type N; def n: N } | ||
|
||
def newS[X](n: X): S { type N = X } = ??? | ||
|
||
def test = | ||
val ss: List[S] = ??? | ||
val cl1 = (s: S) => newS(s.n) | ||
val cl2: (s: S) => S { type N = s.N } = cl1 | ||
def f[R](cl: (s: S) => R) = cl | ||
val x = f(s => newS(s.n)) | ||
val x1: (s: S) => S = x | ||
// If the code in `tptProto` of Namer that refers to this | ||
// file is commented out, we see: | ||
// pickling difference for the result type of the closure argument | ||
// before pickling: S => S { type N = s.N } | ||
// after pickling : (s: S) => S { type N = s.N } | ||
|
||
ss.map(s => newS(s.n)) | ||
// If the code in `tptProto` of Namer that refers to this | ||
// file is commented out, we see a pickling difference like the one above. | ||
|
||
def g[R](cl: (s: S) => (S { type N = s.N }, R)) = ??? | ||
g(s => (newS(s.n), identity(1))) | ||
|
||
def h(cl: (s: S) => S { type N = s.N }) = ??? | ||
h(s => newS(s.n)) | ||
|