diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 4fea51d67d7..dbaaff4546e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2140,6 +2140,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt"); } + @Test + @TestMetadata("JCTree.kt") + public void testJCTree() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/JCTree.kt"); + } + @Test @TestMetadata("kt43342.kt") public void testKt43342() throws Exception { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt index 2eced88dafa..5fc4615bae1 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt @@ -22,10 +22,7 @@ import org.jetbrains.kotlin.fir.resolve.scope import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol +import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor import org.jetbrains.kotlin.ir.IrElement @@ -298,7 +295,7 @@ class Fir2IrImplicitCastInserter( return implicitCastOrExpression(value, castTypeRef) } val referencedSymbol = calleeReference.resolvedSymbol - if (referencedSymbol !is FirPropertySymbol && referencedSymbol !is FirFunctionSymbol) { + if (referencedSymbol !is FirPropertySymbol && referencedSymbol !is FirFunctionSymbol && referencedSymbol !is FirFieldSymbol) { return implicitCastOrExpression(value, castTypeRef) } @@ -339,7 +336,7 @@ class Fir2IrImplicitCastInserter( } } when (referencedSymbol) { - is FirPropertySymbol -> scope.processPropertiesByName(name, processor) + is FirPropertySymbol, is FirFieldSymbol -> scope.processPropertiesByName(name, processor) is FirFunctionSymbol -> scope.processFunctionsByName(name, processor) } return result diff --git a/compiler/testData/ir/irText/firProblems/JCTree.fir.kt.txt b/compiler/testData/ir/irText/firProblems/JCTree.fir.kt.txt new file mode 100644 index 00000000000..4d37bdfb27f --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/JCTree.fir.kt.txt @@ -0,0 +1,21 @@ +class Owner { + constructor(tree: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val tree: T + field = tree + get + + val foo: String + get(): String { + var tree: JCTree = .() + when { + tree /*as T */ is JCTypeApply -> return tree /*as JCTypeApply */.#clazz /*!! String */ + } + return "" + } + +} diff --git a/compiler/testData/ir/irText/firProblems/JCTree.fir.txt b/compiler/testData/ir/irText/firProblems/JCTree.fir.txt new file mode 100644 index 00000000000..be83543c676 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/JCTree.fir.txt @@ -0,0 +1,53 @@ +FILE fqName: fileName:/JCTreeUser.kt + CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Owner.Owner> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[.JCTree] + CONSTRUCTOR visibility:public <> (tree:T of .Owner) returnType:.Owner.Owner> [primary] + VALUE_PARAMETER name:tree index:0 type:T of .Owner + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:tree visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:tree type:T of .Owner visibility:private [final] + EXPRESSION_BODY + GET_VAR 'tree: T of .Owner declared in .Owner.' type=T of .Owner origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Owner.Owner>) returnType:T of .Owner + correspondingProperty: PROPERTY name:tree visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Owner.Owner> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): T of .Owner declared in .Owner' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:tree type:T of .Owner visibility:private [final]' type=T of .Owner origin=null + receiver: GET_VAR ': .Owner.Owner> declared in .Owner.' type=.Owner.Owner> origin=null + PROPERTY name:foo visibility:public modality:FINAL [val] + FUN name: visibility:public modality:FINAL <> ($this:.Owner.Owner>) returnType:kotlin.String + correspondingProperty: PROPERTY name:foo visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Owner.Owner> + BLOCK_BODY + VAR name:tree type:.JCTree [var] + CALL 'public final fun (): T of .Owner declared in .Owner' type=T of .Owner origin=GET_PROPERTY + $this: GET_VAR ': .Owner.Owner> declared in .Owner.' type=.Owner.Owner> origin=null + WHEN type=kotlin.Unit origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.JCTree.JCTypeApply + TYPE_OP type=T of .Owner origin=IMPLICIT_CAST typeOperand=T of .Owner + GET_VAR 'var tree: .JCTree [var] declared in .Owner.' type=.JCTree origin=null + then: RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Owner' + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:clazz type:kotlin.String? visibility:public' type=kotlin.String? origin=GET_PROPERTY + receiver: TYPE_OP type=.JCTree.JCTypeApply origin=IMPLICIT_CAST typeOperand=.JCTree.JCTypeApply + GET_VAR 'var tree: .JCTree [var] declared in .Owner.' type=.JCTree origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Owner' + CONST String type=kotlin.String value="" + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/firProblems/JCTree.kt b/compiler/testData/ir/irText/firProblems/JCTree.kt new file mode 100644 index 00000000000..79049f24ba7 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/JCTree.kt @@ -0,0 +1,24 @@ +// FILE: JCTree.java + +public class JCTree { + public abstract static class JCExpression extends JCTree { + + } + + public static class JCTypeApply extends JCExpression { + public String clazz = "OK"; + } +} + +// FILE: JCTreeUser.kt + +class Owner(val tree: T) { + val foo: String + get() { + var tree: JCTree = tree + if (tree is JCTree.JCTypeApply) { + return tree.clazz + } + return ""; + } +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/firProblems/JCTree.kt.txt b/compiler/testData/ir/irText/firProblems/JCTree.kt.txt new file mode 100644 index 00000000000..6d7b4d32379 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/JCTree.kt.txt @@ -0,0 +1,23 @@ +class Owner { + constructor(tree: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val tree: T + field = tree + get + + val foo: String + get(): String { + var tree: JCTree = .() + when { + tree is JCTypeApply -> { // BLOCK + return tree /*as JCTypeApply */super.#clazz /*!! String */ + } + } + return "" + } + +} diff --git a/compiler/testData/ir/irText/firProblems/JCTree.txt b/compiler/testData/ir/irText/firProblems/JCTree.txt new file mode 100644 index 00000000000..ae397bf6bd5 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/JCTree.txt @@ -0,0 +1,53 @@ +FILE fqName: fileName:/JCTreeUser.kt + CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Owner.Owner> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[.JCTree] + CONSTRUCTOR visibility:public <> (tree:T of .Owner) returnType:.Owner.Owner> [primary] + VALUE_PARAMETER name:tree index:0 type:T of .Owner + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Owner modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:tree visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:tree type:T of .Owner visibility:private [final] + EXPRESSION_BODY + GET_VAR 'tree: T of .Owner declared in .Owner.' type=T of .Owner origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Owner.Owner>) returnType:T of .Owner + correspondingProperty: PROPERTY name:tree visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Owner.Owner> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): T of .Owner declared in .Owner' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:tree type:T of .Owner visibility:private [final]' type=T of .Owner origin=null + receiver: GET_VAR ': .Owner.Owner> declared in .Owner.' type=.Owner.Owner> origin=null + PROPERTY name:foo visibility:public modality:FINAL [val] + FUN name: visibility:public modality:FINAL <> ($this:.Owner.Owner>) returnType:kotlin.String + correspondingProperty: PROPERTY name:foo visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Owner.Owner> + BLOCK_BODY + VAR name:tree type:.JCTree [var] + CALL 'public final fun (): T of .Owner declared in .Owner' type=T of .Owner origin=GET_PROPERTY + $this: GET_VAR ': .Owner.Owner> declared in .Owner.' type=.Owner.Owner> origin=null + WHEN type=kotlin.Unit origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.JCTree.JCTypeApply + GET_VAR 'var tree: .JCTree [var] declared in .Owner.' type=.JCTree origin=null + then: BLOCK type=kotlin.Unit origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Owner' + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:clazz type:@[FlexibleNullability] kotlin.String? visibility:public' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY + receiver: TYPE_OP type=.JCTree.JCTypeApply origin=IMPLICIT_CAST typeOperand=.JCTree.JCTypeApply + GET_VAR 'var tree: .JCTree [var] declared in .Owner.' type=.JCTree origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Owner' + CONST String type=kotlin.String value="" + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index c86e4d91531..17b78e950d7 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2140,6 +2140,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/firProblems/InnerClassInAnonymous.kt"); } + @Test + @TestMetadata("JCTree.kt") + public void testJCTree() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/JCTree.kt"); + } + @Test @TestMetadata("kt43342.kt") public void testKt43342() throws Exception {