@@ -196,11 +196,11 @@ class Namer { typer: Typer =>
196196
197197 import untpd ._
198198
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
201201 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
204204
205205 /** A partial map from unexpanded member and pattern defs and to their expansions.
206206 * Populated during enterSyms, emptied during typer.
@@ -1409,26 +1409,30 @@ class Namer { typer: Typer =>
14091409 * the corresponding parameter where bound parameters are replaced by
14101410 * Wildcards.
14111411 */
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+ }
14321436
14331437 // println(s"final inherited for $sym: ${inherited.toString}") !!!
14341438 // println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}")
@@ -1443,7 +1447,12 @@ class Namer { typer: Typer =>
14431447 val tp1 = tp.widenTermRefExpr.simplified match
14441448 case ctp : ConstantType if isInlineVal => ctp
14451449 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+ }
14471456 tp1.dropRepeatedAnnot
14481457 }
14491458
@@ -1496,26 +1505,13 @@ class Namer { typer: Typer =>
14961505 val tpe = tpFun(paramss.head)
14971506 if (isFullyDefined(tpe, ForceDegree .none)) tpe
14981507 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
15121508 case _ =>
15131509 WildcardType
15141510 }
1515- val memTpe = paramFn(checkSimpleKinded(typedAheadType(mdef.tpt, tptProto)).tpe)
1511+ val mbrTpe = paramFn(checkSimpleKinded(typedAheadType(mdef.tpt, tptProto)).tpe)
15161512 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
15191515 }
15201516
15211517 /** The type signature of a DefDef with given symbol */
0 commit comments