Fix access to scoped symbol table when inserting implicit casts to IR

This commit is contained in:
Svyatoslav Scherbina
2018-03-07 10:29:55 +03:00
parent d38258d7a0
commit d3ab86db48
3 changed files with 58 additions and 5 deletions
@@ -21,10 +21,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
@@ -153,6 +150,11 @@ class InsertImplicitCasts(private val builtIns: KotlinBuiltIns, private val symb
}
}
override fun visitClass(declaration: IrClass): IrStatement =
runInTypeParameterScope(declaration) {
super.visitClass(declaration)
}
override fun visitWhen(expression: IrWhen): IrExpression =
expression.transformPostfix {
for (irBranch in branches) {
@@ -4,4 +4,13 @@ inline fun <reified T : Any> Any.test1(): T? =
interface Foo<T>
inline val <reified T : Any> Foo<T>.asT: T?
get() = if (this is T) this else null
get() = if (this is T) this else null
class Bar<T> {
fun test(arg: Any) {
arg as T
useT(arg)
}
fun useT(t: T) {}
}
@@ -56,3 +56,45 @@ FILE fqName:<root> fileName:/implicitCastToTypeParameter.kt
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
CLASS CLASS name:Bar modality:FINAL visibility:public flags:
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:Bar<T> flags:
superClasses:
CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags:
TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?]
superClassifiers:
CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags:
CONSTRUCTOR visibility:public <> () returnType:Bar<T> flags:
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'constructor Any()'
INSTANCE_INITIALIZER_CALL classDescriptor='Bar'
FUN name:test visibility:public modality:FINAL <> ($this:Bar<T>, arg:kotlin.Any) returnType:Unit flags:
$this: VALUE_PARAMETER name:<this> type:Bar<T> flags:
VALUE_PARAMETER name:arg index:0 type:kotlin.Any flags:
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
typeOperand: CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public flags:
TYPE_OP type=T origin=CAST typeOperand=T
typeOperand: TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?]
GET_VAR 'value-parameter arg: Any' type=kotlin.Any origin=null
CALL 'useT(T): Unit' type=kotlin.Unit origin=null
$this: GET_VAR 'this@Bar: Bar<T>' type=Bar<T> origin=null
t: TYPE_OP type=T origin=IMPLICIT_CAST typeOperand=T
typeOperand: TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?]
GET_VAR 'value-parameter arg: Any' type=kotlin.Any origin=null
FUN name:useT visibility:public modality:FINAL <> ($this:Bar<T>, t:T) returnType:Unit flags:
$this: VALUE_PARAMETER name:<this> type:Bar<T> flags:
VALUE_PARAMETER name:t index:0 type:T flags:
BLOCK_BODY
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags:
overridden:
FUN IR_EXTERNAL_DECLARATION_STUB name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags:
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags:
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags:
overridden:
FUN IR_EXTERNAL_DECLARATION_STUB name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags:
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags:
overridden:
FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags:
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags: