KT-56687: Unify handling of EnumEntries.

`supportsEnumEntries` in `EnumCLassLowering` is not really
needed, but it was left just in case.
Both K1 and K2 ensure the feature is
enabled before they generate IR.

`supportsEnumEntries` is not enough, because the frontend will not
generate `entries` if `kotlin.enums.EnumEntries` is not available
(linking against an outdated stdlib is considered a valid use-case).

From the resolution point of view,
it's OK to resolve into `entries` while
the feature is off, because then K1 reports an error on the call site.

^KT-56687 Fixed
^KT-55614 Fixed
This commit is contained in:
Nikolay Lunyak
2023-02-16 13:06:22 +02:00
committed by Space Team
parent bcfafc601e
commit bb368bd191
14 changed files with 164 additions and 18 deletions
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.replaceText
import org.junit.jupiter.api.DisplayName
@DisplayName("EnumEntries feature test when no kotlin.enums.EnumEntries found on the classpath")
@JvmGradlePluginTests
class EnumEntriesWithOutdatedStdlibTest : KGPBaseTest() {
@DisplayName("EnumEntries should not be accessible without kotlin.enums.EnumEntries")
@GradleTest
fun enumEntriesNotAccessible(gradleVersion: GradleVersion) {
project("enumEntriesNotAccessible", gradleVersion) {
buildGradleKts.replaceText("\"<language-version>\"", "\"1.9\" // <language-version>")
buildAndFail(":compileKotlin") {
assertOutputContains("Main.kt:13:20 Unresolved reference: entries")
assertOutputContains("Main.kt:14:30 Unresolved reference: entries")
}
buildGradleKts.replaceText("\"1.9\" // <language-version>", "\"2.0\" // <language-version>")
buildAndFail(":compileKotlin") {
assertOutputContains("Main.kt:13:20 Unresolved reference: entries")
assertOutputContains("Main.kt:14:30 Unresolved reference: entries")
}
}
}
@DisplayName("Code should compile normally if `entries` is never referenced")
@GradleTest
fun codeCompilesWithoutReferencingEntries(gradleVersion: GradleVersion) {
project("enumEntriesNotAccessible", gradleVersion) {
projectPath.resolve("src/main/kotlin/Main.kt")
.replaceText("entries", "values()")
buildGradleKts.replaceText("\"<language-version>\"", "\"1.9\" // <language-version>")
build(":compileKotlin")
buildGradleKts.replaceText("\"1.9\" // <language-version>", "\"2.0\" // <language-version>")
build(":compileKotlin")
}
}
}
@@ -0,0 +1,24 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
}
group = "com.example"
version = "1.0"
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.20")
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.languageVersion = "<language-version>"
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package com.example
enum class MyEnum {
A, B
}
fun main() {
val a = MyEnum.entries
val b = AnnotationTarget.entries
println("$a :: $b")
}