Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6fc2202

Browse files
committed
Revert "Stop generating generic signatures for mixin forwarders"
This reverts commit 162647c.
1 parent 52bb0c3 commit 6fc2202

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/compiler/scala/tools/nsc/transform/Mixin.scala

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,33 @@ abstract class Mixin extends Transform with ast.TreeDSL with AccessorSynthesis {
169169
clazz.info.decls enter member setFlag MIXEDIN resetFlag JAVA_DEFAULTMETHOD
170170
}
171171
def cloneAndAddMember(mixinClass: Symbol, mixinMember: Symbol, clazz: Symbol): Symbol =
172-
addMember(clazz, mixinMember.cloneSymbol(clazz).setFlag(BRIDGE))
172+
addMember(clazz, cloneBeforeErasure(mixinClass, mixinMember, clazz).setFlag(BRIDGE))
173+
174+
def cloneBeforeErasure(mixinClass: Symbol, mixinMember: Symbol, clazz: Symbol): Symbol = {
175+
val newSym = enteringErasure {
176+
// since we used `mixinMember` from the interface that represents the trait that's
177+
// being mixed in, have to instantiate the interface type params (that may occur in mixinMember's
178+
// info) as they are seen from the class. We can't use the member that we get from the
179+
// implementation class, as it's a clone that was made after erasure, and thus it does not
180+
// know its info at the beginning of erasure anymore.
181+
val sym = mixinMember cloneSymbol clazz
182+
183+
val erasureMap = erasure.erasure(mixinMember)
184+
val erasedInterfaceInfo: Type = erasureMap(mixinMember.info)
185+
val specificForwardInfo = (clazz.thisType baseType mixinClass) memberInfo mixinMember
186+
val forwarderInfo =
187+
if (erasureMap(specificForwardInfo) =:= erasedInterfaceInfo)
188+
specificForwardInfo
189+
else {
190+
erasedInterfaceInfo
191+
}
192+
// Optimize: no need if mixinClass has no typeparams.
193+
// !!! JZ Really? What about the effect of abstract types, prefix?
194+
if (mixinClass.typeParams.isEmpty) sym
195+
else sym modifyInfo (_ => forwarderInfo)
196+
}
197+
newSym
198+
}
173199

174200
def publicizeTraitMethods(clazz: Symbol): Unit = {
175201
if (treatedClassInfos(clazz) != clazz.info) {

test/files/neg/t5148.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
t5148.scala:4: error: Symbol 'type scala.tools.nsc.interpreter.IMain.Request' is missing from the classpath.
1+
t5148.scala:4: error: Symbol 'term scala.tools.nsc.interpreter.IMain.memberHandlers' is missing from the classpath.
22
This symbol is required by 'method scala.tools.nsc.interpreter.Imports.allReqAndHandlers'.
3-
Make sure that type Request is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
3+
Make sure that term memberHandlers is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
44
A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain.
55
class IMain extends Imports
66
^

0 commit comments

Comments
 (0)