[FIR2IR] Allow to get cached symbols in fake override generator

This commit is contained in:
Mikhail Glukhikh
2020-06-26 18:01:20 +03:00
parent c4d41f48a3
commit 69ec8f2d89
@@ -79,7 +79,15 @@ class FakeOverrideGenerator(
(functionSymbol.callableId.classId == klass.symbol.classId || fakeOverrideMode == FakeOverrideMode.SUBSTITUTION) (functionSymbol.callableId.classId == klass.symbol.classId || fakeOverrideMode == FakeOverrideMode.SUBSTITUTION)
) { ) {
// Substitution case // Substitution case
val irFunction = declarationStorage.createIrFunction( // NB: we can get same substituted FIR fake override in a different class, if it derives the same genetic type
// open class Base<T> {
// fun foo(): T
// }
// class Derived1 : Base<String>() {}
// class Derived2 : Base<String>() {}
// That's why we must check parent during caching...
val irFunction = declarationStorage.getCachedIrFunction(originalFunction)?.takeIf { it.parent == this }
?: declarationStorage.createIrFunction(
originalFunction, irParent = this, originalFunction, irParent = this,
thisReceiverOwner = declarationStorage.findIrParent(baseSymbol.fir) as? IrClass, thisReceiverOwner = declarationStorage.findIrParent(baseSymbol.fir) as? IrClass,
origin = origin origin = origin
@@ -127,7 +135,9 @@ class FakeOverrideGenerator(
(propertySymbol.callableId.classId == klass.symbol.classId || fakeOverrideMode == FakeOverrideMode.SUBSTITUTION) (propertySymbol.callableId.classId == klass.symbol.classId || fakeOverrideMode == FakeOverrideMode.SUBSTITUTION)
) { ) {
// Substitution case // Substitution case
val irProperty = declarationStorage.createIrProperty( // NB: see comment above about substituted function' parent
val irProperty = declarationStorage.getCachedIrProperty(originalProperty)?.takeIf { it.parent == this}
?: declarationStorage.createIrProperty(
originalProperty, irParent = this, originalProperty, irParent = this,
thisReceiverOwner = declarationStorage.findIrParent(baseSymbol.fir) as? IrClass, thisReceiverOwner = declarationStorage.findIrParent(baseSymbol.fir) as? IrClass,
origin = origin origin = origin