@@ -196,11 +196,11 @@ class Namer { typer: Typer =>
196
196
197
197
import untpd ._
198
198
199
- val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
200
- val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
199
+ val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
200
+ val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
201
201
val ExportForwarders : Property .Key [List [tpd.MemberDef ]] = new Property .Key
202
- val SymOfTree : Property .Key [Symbol ] = new Property .Key
203
- val Deriver : Property .Key [typer.Deriver ] = new Property .Key
202
+ val SymOfTree : Property .Key [Symbol ] = new Property .Key
203
+ val Deriver : Property .Key [typer.Deriver ] = new Property .Key
204
204
205
205
/** A partial map from unexpanded member and pattern defs and to their expansions.
206
206
* Populated during enterSyms, emptied during typer.
@@ -1409,26 +1409,30 @@ class Namer { typer: Typer =>
1409
1409
* the corresponding parameter where bound parameters are replaced by
1410
1410
* Wildcards.
1411
1411
*/
1412
- def rhsProto = sym.asTerm.name collect {
1413
- case DefaultGetterName (original, idx) =>
1414
- val meth : Denotation =
1415
- if (original.isConstructorName && (sym.owner.is(ModuleClass )))
1416
- sym.owner.companionClass.info.decl(nme.CONSTRUCTOR )
1417
- else
1418
- ctx.defContext(sym).denotNamed(original)
1419
- def paramProto (paramss : List [List [Type ]], idx : Int ): Type = paramss match {
1420
- case params :: paramss1 =>
1421
- if (idx < params.length) wildApprox(params(idx))
1422
- else paramProto(paramss1, idx - params.length)
1423
- case nil =>
1424
- WildcardType
1425
- }
1426
- val defaultAlts = meth.altsWith(_.hasDefaultParams)
1427
- if (defaultAlts.length == 1 )
1428
- paramProto(defaultAlts.head.info.widen.paramInfoss, idx)
1429
- else
1430
- WildcardType
1431
- } getOrElse WildcardType
1412
+ def rhsProto = mdef.tpt.getAttachment(Typer .RhsProto )
1413
+ .getOrElse {{
1414
+ sym.asTerm.name collect {
1415
+ case DefaultGetterName (original, idx) =>
1416
+ val meth : Denotation =
1417
+ if (original.isConstructorName && (sym.owner.is(ModuleClass )))
1418
+ sym.owner.companionClass.info.decl(nme.CONSTRUCTOR )
1419
+ else
1420
+ ctx.defContext(sym).denotNamed(original)
1421
+ def paramProto (paramss : List [List [Type ]], idx : Int ): Type = paramss match {
1422
+ case params :: paramss1 =>
1423
+ if (idx < params.length) wildApprox(params(idx))
1424
+ else paramProto(paramss1, idx - params.length)
1425
+ case nil =>
1426
+ WildcardType
1427
+ }
1428
+ val defaultAlts = meth.altsWith(_.hasDefaultParams)
1429
+ if (defaultAlts.length == 1 )
1430
+ paramProto(defaultAlts.head.info.widen.paramInfoss, idx)
1431
+ else
1432
+ WildcardType
1433
+ }
1434
+ }.getOrElse(WildcardType )
1435
+ }
1432
1436
1433
1437
// println(s"final inherited for $sym: ${inherited.toString}") !!!
1434
1438
// println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}")
@@ -1443,7 +1447,12 @@ class Namer { typer: Typer =>
1443
1447
val tp1 = tp.widenTermRefExpr.simplified match
1444
1448
case ctp : ConstantType if isInlineVal => ctp
1445
1449
case ref : TypeRef if ref.symbol.is(ModuleClass ) => tp
1446
- case tp => tp.widenUnion
1450
+ case tp =>
1451
+ if true then ctx.typeComparer.widenInferred(tp, rhsProto)
1452
+ else rhsProto match {
1453
+ case OrType (_, _) | WildcardType (TypeBounds (_, OrType (_, _))) => tp.widen
1454
+ case _ => tp.widenUnion
1455
+ }
1447
1456
tp1.dropRepeatedAnnot
1448
1457
}
1449
1458
@@ -1496,26 +1505,13 @@ class Namer { typer: Typer =>
1496
1505
val tpe = tpFun(paramss.head)
1497
1506
if (isFullyDefined(tpe, ForceDegree .none)) tpe
1498
1507
else typedAheadExpr(mdef.rhs, tpe).tpe
1499
- case TypedSplice (tpt : TypeTree ) if ! isFullyDefined(tpt.tpe, ForceDegree .none) =>
1500
- val rhsType = typedAheadExpr(mdef.rhs, tpt.tpe).tpe
1501
- mdef match {
1502
- case mdef : DefDef if mdef.name == nme.ANON_FUN =>
1503
- val hygienicType = avoid(rhsType, paramss.flatten)
1504
- if (! hygienicType.isValueType || ! (hygienicType <:< tpt.tpe))
1505
- ctx.error(i " return type ${tpt.tpe} of lambda cannot be made hygienic; \n " +
1506
- i " it is not a supertype of the hygienic type $hygienicType" , mdef.sourcePos)
1507
- // println(i"lifting $rhsType over $paramss -> $hygienicType = ${tpt.tpe}")
1508
- // println(TypeComparer.explained { implicit ctx => hygienicType <:< tpt.tpe })
1509
- case _ =>
1510
- }
1511
- WildcardType
1512
1508
case _ =>
1513
1509
WildcardType
1514
1510
}
1515
- val memTpe = paramFn(checkSimpleKinded(typedAheadType(mdef.tpt, tptProto)).tpe)
1511
+ val mbrTpe = paramFn(checkSimpleKinded(typedAheadType(mdef.tpt, tptProto)).tpe)
1516
1512
if (ctx.explicitNulls && mdef.mods.is(JavaDefined ))
1517
- JavaNullInterop .nullifyMember(sym, memTpe , mdef.mods.isAllOf(JavaEnumValue ))
1518
- else memTpe
1513
+ JavaNullInterop .nullifyMember(sym, mbrTpe , mdef.mods.isAllOf(JavaEnumValue ))
1514
+ else mbrTpe
1519
1515
}
1520
1516
1521
1517
/** The type signature of a DefDef with given symbol */
0 commit comments