diff options
author | Martin Odersky <odersky@gmail.com> | 2016-06-08 09:45:56 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-07-11 13:35:02 +0200 |
commit | f1bf78bf8ceb17bfe0b9dc57a6e6f03a9b59065f (patch) | |
tree | 394d08b0a35d420e86fa08642362426d27736aa9 /src/dotty/tools/dotc/typer/Typer.scala | |
parent | 5041e9311bf1845d09c6eeccba816214fe25a3e6 (diff) | |
download | dotty-f1bf78bf8ceb17bfe0b9dc57a6e6f03a9b59065f.tar.gz dotty-f1bf78bf8ceb17bfe0b9dc57a6e6f03a9b59065f.tar.bz2 dotty-f1bf78bf8ceb17bfe0b9dc57a6e6f03a9b59065f.zip |
Avoid creating dependent function types for closures
Without this step, anonymous functions can have dependent
types which causes the parameter references to "leak out"
to types in the environment in illegal ways. This caused
a tasty failure for Typer before (not sure why the failure
was not observed under the old hk scheme).
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 34be65591..96bc2ab35 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1042,7 +1042,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef]) val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef]) if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1) - val tpt1 = checkSimpleKinded(typedType(tpt)) + var tpt1 = checkSimpleKinded(typedType(tpt)) var rhsCtx = ctx if (sym.isConstructor && !sym.isPrimaryConstructor && tparams1.nonEmpty) { @@ -1054,6 +1054,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit rhsCtx.gadt.setBounds(tdef.symbol, TypeAlias(tparam.typeRef))) } val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx) + if (sym.isAnonymousFunction) { + // If we define an anonymous function, make sure the return type does not + // refer to parameters. This is necessary because closure types are + // function types so no dependencies on parameters are allowed. + tpt1 = tpt1.withType(avoid(tpt1.tpe, vparamss1.flatMap(_.map(_.symbol)))) + } assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym) //todo: make sure dependent method types do not depend on implicits or by-name params } |