From 9ea775cbede4ad6b4f504f6a568e8c65798f6761 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 19 Feb 2024 15:24:08 +0100 Subject: [PATCH] K2 scripting: fix containing decl for last script expression Generally the wrapping anonymous initializer can be used as a "containing declaration" for some elements, but since the initialiser for the last script expression could be dropped (the expression could be converted to the result property), this may lead to the surprises, e.g. as described in KT-65984 This fix marks the last initialiser as local, preventing it from being referenced as "containing declaration". #KT-65984 --- .../property/resultBodyAnnotation.after.txt | 34 ++ .../property/resultBodyAnnotation.before.txt | 34 ++ .../property/resultBodyAnnotation.kts | 16 + .../resultBodyAnnotation.lazyResolve.txt | 339 ++++++++++++++++++ ...esolveForTypeAnnotationsTestGenerated.java | 6 + ...criptLazyTypeAnnotationsTestGenerated.java | 6 + ...CompilerTestFE10TestdataTestGenerated.java | 6 + ...sticCompilerFE10TestDataTestGenerated.java | 6 + ...siOldFrontendDiagnosticsTestGenerated.java | 6 + .../kotlin/fir/builder/PsiRawFirBuilder.kt | 14 +- ...tationAsLastStatement.annotationOwners.txt | 12 +- .../script/SuppressAnnoInLastExpression.kts | 3 + .../test/runners/DiagnosticTestGenerated.java | 6 + 13 files changed, 481 insertions(+), 7 deletions(-) create mode 100644 analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.after.txt create mode 100644 analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.before.txt create mode 100644 analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.kts create mode 100644 analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.lazyResolve.txt create mode 100644 compiler/testData/diagnostics/tests/script/SuppressAnnoInLastExpression.kts diff --git a/analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.after.txt b/analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.after.txt new file mode 100644 index 00000000000..cbbef6a7377 --- /dev/null +++ b/analysis/low-level-api-fir/testData/lazyResolveTypeAnnotations/property/resultBodyAnnotation.after.txt @@ -0,0 +1,34 @@ +@R|foo/Anno|(position = (String(local type ), R|foo/constant|)) kotlin/Int + context -> FirPropertySymbol /i + anchor -> [FirPropertySymbol /$$result] + +@R|foo/Anno|(position = (String(local type ), R|foo/constant|)) kotlin/Int + context -> FirBackingFieldSymbol /field from FirPropertySymbol /i + anchor -> [FirPropertySymbol /$$result] + +FILE: [ResolvedTo(IMPORTS)] resultBodyAnnotation.kts + context(