diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-10-12 23:40:15 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-10-14 10:00:18 +0200 |
commit | 4f1a46c98afeeb57bd79d339c2be3280cdb41273 (patch) | |
tree | f5a3b167fa364d03a865b031daec84020978c763 /src/compiler/scala/tools/nsc/typechecker/Infer.scala | |
parent | 810ce7e2790e4da4e3f1d9473ccad5a721847096 (diff) | |
download | scala-4f1a46c98afeeb57bd79d339c2be3280cdb41273.tar.gz scala-4f1a46c98afeeb57bd79d339c2be3280cdb41273.tar.bz2 scala-4f1a46c98afeeb57bd79d339c2be3280cdb41273.zip |
SI-7899 Allow by-name inference under -Yinfer-by-name
As usual, the hole has been exploited in the wild. While you
can't abstract over by-name-ness without running into the
ClassCastException or an un-applied Function0, there are cases
like the enclosed test where you can tiptoe around those
cases.
I've proposed a small change to Scalaz to avoid tripping over
this problem:
https://github.com/scalaz/scalaz/pull/562/files
But this commit I've also added a transitional flag, -Yinfer-by-name,
that they could use to back-publish older versions without code
changes. It is also an insurance policy for other projects that
might be exploiting the same hole.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Infer.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index ccf4a5e46f..dd0923a696 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -913,7 +913,11 @@ trait Infer extends Checkable { val targs = exprTypeArgs(tvars, tparams, treeTp, pt, useWeaklyCompatible) def infer_s = map3(tparams, tvars, targs)((tparam, tvar, targ) => s"$tparam=$tvar/$targ") mkString "," printTyping(tree, s"infer expr instance from pt=$pt, $infer_s") - def targsStrict = if (targs eq null) null else targs mapConserve dropByName + + // SI-7899 infering by-name types is unsound. The correct behaviour is conditional because the hole is + // exploited in Scalaz (Free.scala), as seen in: run/t7899-regression. + def dropByNameIfStrict(tp: Type): Type = if (settings.inferByName) tp else dropByName(tp) + def targsStrict = if (targs eq null) null else targs mapConserve dropByNameIfStrict if (keepNothings || (targs eq null)) { //@M: adjustTypeArgs fails if targs==null, neg/t0226 substExpr(tree, tparams, targsStrict, pt) |