diff options
author | Martin Odersky <odersky@gmail.com> | 2016-03-25 10:37:28 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-03-30 09:51:03 +0200 |
commit | c03c8ca068b61bc7cee97dbc9e183bb3e410b839 (patch) | |
tree | d11ce8d780ccc0758575aea80dbeb98c5919f4f0 /src/dotty/tools/dotc/core/Types.scala | |
parent | d0f9848486be2c8cec61acb94a592e8c9d4f842f (diff) | |
download | dotty-c03c8ca068b61bc7cee97dbc9e183bb3e410b839.tar.gz dotty-c03c8ca068b61bc7cee97dbc9e183bb3e410b839.tar.bz2 dotty-c03c8ca068b61bc7cee97dbc9e183bb3e410b839.zip |
Take named type parameters into account when instantiating variables.
When instantiating a type variable, make the instance has the same named
type parameters as the upper bound. This is the analogue of kind-correctness
for named type parameters.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index ffb662490..c39af1430 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2643,7 +2643,7 @@ object Types { // First, solve the constraint. var inst = ctx.typeComparer.approximation(origin, fromBelow) - // Then, approximate by (1.) and (2.) and simplify as follows. + // Then, approximate by (1.) - (3.) and simplify as follows. // 1. If instance is from below and is a singleton type, yet // upper bound is not a singleton type, widen the instance. if (fromBelow && isSingleton(inst) && !isSingleton(upperBound)) @@ -2657,6 +2657,10 @@ object Types { if (fromBelow && isOrType(inst) && isFullyDefined(inst) && !isOrType(upperBound)) inst = inst.approximateUnion + // 3. If instance is from below, and upper bound has open named parameters + // make sure the instance has all named parameters of the bound. + if (fromBelow) inst = inst.widenToNamedTypeParams(this.namedTypeParams) + if (ctx.typerState.isGlobalCommittable) assert(!inst.isInstanceOf[PolyParam], i"bad inst $this := $inst, constr = ${ctx.typerState.constraint}") // If this fails, you might want to turn on Config.debugCheckConstraintsClosed |