aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 3d36905f2..10d7516e6 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1022,17 +1022,20 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val DefDef(name, tparams, vparamss, tpt, _) = ddef
completeAnnotations(ddef, sym)
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
- // for secondary constructors we need to use that their type parameters
- // are aliases of the class type parameters. See pos/i941.scala
- if (sym.isConstructor && !sym.isPrimaryConstructor)
- (sym.owner.typeParams, tparams1).zipped.foreach {(tparam, tdef) =>
- tdef.symbol.info = TypeAlias(tparam.typeRef)
- }
-
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1)
val tpt1 = checkSimpleKinded(typedType(tpt))
- val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)
+
+ var rhsCtx = ctx
+ if (sym.isConstructor && !sym.isPrimaryConstructor && tparams1.nonEmpty) {
+ // for secondary constructors we need a context that "knows"
+ // that their type parameters are aliases of the class type parameters.
+ // See pos/i941.scala
+ rhsCtx = ctx.fresh.setFreshGADTBounds
+ (tparams1, sym.owner.typeParams).zipped.foreach ((tdef, tparam) =>
+ rhsCtx.gadt.setBounds(tdef.symbol, TypeAlias(tparam.typeRef)))
+ }
+ val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx)
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
}