@@ -1025,6 +1025,11 @@ class Typer extends Namer
1025
1025
1026
1026
/** gadtSyms = "all type parameters of enclosing methods appearing in selector type" */
1027
1027
def gadtSyms (selType : Type )(implicit ctx : Context ): Set [Symbol ] = trace(i " GADT syms of $selType" , gadts) {
1028
+ // def enclosingRealMethod(sym: Symbol): Symbol =
1029
+ // if (sym.isRealMethod) sym else if (sym.exists) enclosingRealMethod(sym) else NoSymbol
1030
+ // val erm = enclosingRealMethod(ctx.owner)
1031
+ // ctx.tree
1032
+ // println(i"gadtSyms: owner=${ctx.owner} erm=$erm info=${erm.initial} mbr=${erm.info.allMembers} candidate=${erm.termRef.widenTermRefExpr.asInstanceOf[PolyType].paramInfoss}%, %")
1028
1033
val accu = new TypeAccumulator [Set [Symbol ]] {
1029
1034
def apply (tsyms : Set [Symbol ], t : Type ): Set [Symbol ] = {
1030
1035
val tsyms1 = t match {
@@ -1520,19 +1525,38 @@ class Typer extends Namer
1520
1525
if (sym is Implicit ) checkImplicitConversionDefOK(sym)
1521
1526
val tpt1 = checkSimpleKinded(typedType(tpt))
1522
1527
1523
- var rhsCtx = ctx
1524
- if (sym.isConstructor && ! sym.isPrimaryConstructor && tparams1.nonEmpty) {
1525
- // for secondary constructors we need a context that "knows"
1526
- // that their type parameters are aliases of the class type parameters.
1527
- // See pos/i941.scala
1528
- rhsCtx = ctx.fresh.setFreshGADTBounds
1529
- (tparams1, sym.owner.typeParams).zipped.foreach { (tdef, tparam) =>
1530
- val tr = tparam.typeRef
1531
- rhsCtx.gadt.addBound(tdef.symbol, tr, isUpper = false )
1532
- rhsCtx.gadt.addBound(tdef.symbol, tr, isUpper = true )
1528
+ val rhsCtx : Context = {
1529
+ var _result : FreshContext = null
1530
+ def resultCtx (): FreshContext = {
1531
+ if (_result == null ) _result = ctx.fresh
1532
+ _result
1533
1533
}
1534
+
1535
+ if (tparams1.nonEmpty) {
1536
+ resultCtx().setFreshGADTBounds
1537
+ if (! sym.isConstructor) {
1538
+ // if we're _not_ in a constructor, allow constraining type parameters
1539
+ tparams1.foreach { tdef =>
1540
+ val TypeBounds (lo, hi) = tdef.symbol.info.bounds
1541
+ resultCtx().gadt.addBound(tdef.symbol, lo, isUpper = false )
1542
+ resultCtx().gadt.addBound(tdef.symbol, hi, isUpper = true )
1543
+ }
1544
+ } else if (! sym.isPrimaryConstructor) {
1545
+ // otherwise, for secondary constructors we need a context that "knows"
1546
+ // that their type parameters are aliases of the class type parameters.
1547
+ // See pos/i941.scala
1548
+ (tparams1, sym.owner.typeParams).zipped.foreach { (tdef, tparam) =>
1549
+ val tr = tparam.typeRef
1550
+ resultCtx().gadt.addBound(tdef.symbol, tr, isUpper = false )
1551
+ resultCtx().gadt.addBound(tdef.symbol, tr, isUpper = true )
1552
+ }
1553
+ }
1554
+ }
1555
+
1556
+ if (sym.isInlineMethod) resultCtx().addMode(Mode .InlineableBody )
1557
+
1558
+ if (_result ne null ) _result else ctx
1534
1559
}
1535
- if (sym.isInlineMethod) rhsCtx = rhsCtx.addMode(Mode .InlineableBody )
1536
1560
val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx)
1537
1561
1538
1562
if (sym.isInlineMethod) PrepareInlineable .registerInlineInfo(sym, ddef.rhs, _ => rhs1)
0 commit comments