diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-02-22 15:53:29 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-04-02 23:37:08 +0200 |
commit | c2534bf61b61b76cebaad09ba303234193709b60 (patch) | |
tree | f06eb1967edd2b3f18fc7994d87d6ce393f6b701 /test/files | |
parent | d7545ec36bde6a21e5f3edb1b5982e801a53f6a9 (diff) | |
download | scala-c2534bf61b61b76cebaad09ba303234193709b60.tar.gz scala-c2534bf61b61b76cebaad09ba303234193709b60.tar.bz2 scala-c2534bf61b61b76cebaad09ba303234193709b60.zip |
SI-6900 Fix tailrec for dependent method types
Uncurry's info transformer could generate a MethodType
with cloned parameter symbols. This type was used
for the LabelDef generated in the TailCalls phase.
But, the RHS of the method still contains types that
refer to the original parmameter symbol. Spurious
type errors ensued.
I've spent a good chunk of time pursuing a more
principled fix, in which we keep the symbols in the
tree in sync with those in the MethodType. You can
relive the procession of false dawns:
https://github.com/scala/scala/pull/2248
Ultimately that scheme was derailed by a mismatch
between the type parameter `T` and the skolem `T&`
in the example below.
trait Endo[A] { def apply(a: => A): A }
class Test {
def foo[T] =
new Endo[(T, Unit)] {
def apply(v1: => (T, Unit)) = v1 // no bridge created
}
}
Interestingly, by removing the caching in SingleType,
I got past that problem. But I didn't characterize it
further.
This commit sets asides the noble goal of operating in
the world of types, and sledgehammers past the crash by
casting the arguments to and the result of the label jump
generated in TailCalls.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t6900.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/files/run/t6900.scala b/test/files/run/t6900.scala new file mode 100644 index 0000000000..a29d388129 --- /dev/null +++ b/test/files/run/t6900.scala @@ -0,0 +1,36 @@ +import annotation.tailrec + +trait Universe { + type T <: AnyRef +} + +final class Bug { + var i = 1 + def stop() = { i -= 1; i < 0 } + // the alias bypasses the fast path in erasures InfoTransformer + // predicated on `TypeMap.noChangeToSymbols` + type Alias = Any + + @tailrec + // So we get two symbols for `universe`, the original on the ValDef + // and a clone in the MethodType of `f`. + def f(universe: Universe, l: Alias): universe.T = { + if (stop()) null.asInstanceOf[universe.T] else f(universe, null) + } + + @tailrec + def g(universe: Universe)(l: Alias): universe.T = { + if (stop()) null.asInstanceOf[universe.T] else g(universe)(l) + } + + @tailrec + def h(universe: Universe)(l: List[universe.T]): List[universe.T] = { + if (stop()) Nil else h(universe)(l) + } +} + +object Test extends App { + assert(new Bug().f(null, null) == null) + assert(new Bug().g(null)(null) == null) + assert(new Bug().h(null)(null) == Nil) +}
\ No newline at end of file |