From 93747cdb576d0a2cb17db1d392e1bdb56e8e6049 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 13 Feb 2015 11:53:09 +0100 Subject: Stop type inference from creating oprphans. A tweak in the answer to a fundamental question of inference: When should type variables be instantiated? Example: In a call f [ TVar ] ( g() ) A syntehsied type variable TVar can be instantiated as soon as the call is fully elaborated, but not before - in particular not when typing the nested call `g()`. This is so far achieved by looking at the `owningTree` of a type variable (in the example it would be the call above) and instantiating only if the current tree contains the owning tree. Problem is that this is fragile. If in the meantime the tree was copied, say due to eta-expansion, the contains test will fail. Now this is not a big deal, as long as we instantiate the type variable eventually. But previously that was never done. With the fix we now instantiate type variables also if we have fully elaborated the definition that closest encloses the point where the type variable is created. This is less fragile, as definitions can be compared using their symbols instead of looking at trees. --- src/dotty/tools/dotc/core/Types.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/core/Types.scala') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 5f30f484e..f113307ef 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2269,8 +2269,12 @@ object Types { * @param creatorState The typer state in which the variable was created. * @param owningTree The function part of the TypeApply tree tree that introduces * the type variable. + * @paran owner The current owner if the context where the variable was created. + * + * `owningTree` and `owner` are used to determine whether a type-variable can be instantiated + * at some given point. See `Inferencing#interpolateUndetVars`. */ - final class TypeVar(val origin: PolyParam, creatorState: TyperState, val owningTree: untpd.Tree) extends CachedProxyType with ValueType { + final class TypeVar(val origin: PolyParam, creatorState: TyperState, val owningTree: untpd.Tree, val owner: Symbol) extends CachedProxyType with ValueType { /** The permanent instance type of the the variable, or NoType is none is given yet */ private[core] var inst: Type = NoType -- cgit v1.2.3