diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-16 15:02:24 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-16 15:30:48 +1000 |
commit | 585cf5a2397210eb37cb01bf5a29771beef21412 (patch) | |
tree | cefa9afc3a03bd8058e63d62399fd2af8316e4c1 /test/files | |
parent | d99785b7c3b99bbb053eb3337262c88548ab50d2 (diff) | |
download | scala-585cf5a2397210eb37cb01bf5a29771beef21412.tar.gz scala-585cf5a2397210eb37cb01bf5a29771beef21412.tar.bz2 scala-585cf5a2397210eb37cb01bf5a29771beef21412.zip |
SI-9401 Avoid SOE with array + missing classtag
The implicit classtags required by the Array constructor are not
expressed in the type signature of its constructor, and instead
are summoned by a special case in the typechecker.
This special case entails replacing the `new Array` tree with
`implicitly[T].newArray(size)`, handled in `ArrayInstantiation`.
This tree is recursively typechecked.
However, if the implicit materialization/search fails, an error
is issued to the current reporter and the original tree is marked
with an error type. As above, this is recursively typechecked.
In the normal course of affairs, the recursive typecheck of the
erroneous tree would be a noop (the tree already has a type!).
However, if we are both in silent mode (in which errors are buffered)
and in retyping mode (in which the typer clears the type and symbols
of trees), we were getting into an cycle.
In the enclosed test, retyping mode was trying to recover
from:
Resetting.this.gencastarray_=(new Array[T](0).<ERROR>)
By inserting a suitable a view:
implicitly[Resetting => { def gencastarray_=(AT)}](
Resetting.this
).gencastarray_=(new Array[T](0))
Where AT is the type found by retypechecking the argument.
It is during the argument retypechecking that we fell into cycle.
Crazily enough, in 2.11.0, the ensuing `StackOverflowError` was
being caught and treated as a failure. We would then back out of
the retyping mode, and issue the error from the the very first attempt
at the implicit search.
This fragile state of affairs was disrupted by a refactoring to
the error reporting system in 725c5c9, after which the SOE crashed
the compiler.
This commit avoids recursively typechecking error typed trees.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/t9401.check | 4 | ||||
-rw-r--r-- | test/files/neg/t9401.scala | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/test/files/neg/t9401.check b/test/files/neg/t9401.check new file mode 100644 index 0000000000..638d56db63 --- /dev/null +++ b/test/files/neg/t9401.check @@ -0,0 +1,4 @@ +t9401.scala:3: error: cannot find class tag for element type T + gencastarray = new Array[T](0) + ^ +one error found diff --git a/test/files/neg/t9401.scala b/test/files/neg/t9401.scala new file mode 100644 index 0000000000..f42ecc7f74 --- /dev/null +++ b/test/files/neg/t9401.scala @@ -0,0 +1,4 @@ +class Resetting[T] { + var gencastarray: Any = null + gencastarray = new Array[T](0) +} |