From 9f0403f72c882dc4365e5e047b2119ca19a87f35 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 6 Feb 2017 19:14:18 +0300 Subject: [PATCH] Fix exception at accidentally wrong annotation argument type #KT-13740 Fixed --- .../kotlin/codegen/ExpressionCodegen.java | 6 +++++- .../const/arrayInAnnotationArgumentType.kt | 2 ++ .../const/arrayInAnnotationArgumentType.txt | 17 +++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt create mode 100644 compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 3c51a44d0fa..b2f26ad60fa 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1518,6 +1518,10 @@ public class ExpressionCodegen extends KtVisitor impleme } KotlinType expectedType = bindingContext.getType(expression); + if (expectedType == null) { + return null; + } + return compileTimeValue.toConstantValue(expectedType); } diff --git a/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt b/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt new file mode 100644 index 00000000000..48c02bc6bf9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt @@ -0,0 +1,2 @@ +annotation class A(val a: IntArray = arrayOf(1)) +annotation class B(val a: IntArray = intArrayOf(1)) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.txt b/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.txt new file mode 100644 index 00000000000..aeb031be66e --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.txt @@ -0,0 +1,17 @@ +package + +public final annotation class A : kotlin.Annotation { + public constructor A(/*0*/ a: kotlin.IntArray = ...) + public final val a: kotlin.IntArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class B : kotlin.Annotation { + public constructor B(/*0*/ a: kotlin.IntArray = ...) + public final val a: kotlin.IntArray + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 8ccebc9cef6..0b111f92fb8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12519,6 +12519,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("arrayInAnnotationArgumentType.kt") + public void testArrayInAnnotationArgumentType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/const/arrayInAnnotationArgumentType.kt"); + doTest(fileName); + } + @TestMetadata("constInteraction.kt") public void testConstInteraction() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/const/constInteraction.kt");