Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include interferes with imports of enum instances #296

Open
reitzig opened this issue Dec 12, 2020 · 2 comments
Open

Include interferes with imports of enum instances #296

reitzig opened this issue Dec 12, 2020 · 2 comments

Comments

@reitzig
Copy link

reitzig commented Dec 12, 2020

Consider this file repro.kts:

import Repro.Foo.Bar

enum class Foo {
    Bar
}

println(Bar)

This runs and prints Bar -- all is well.
Now, add an include directive (file can be empty):

@file:Include("shared.kt")

import Repro.Foo.Bar

enum class Foo {
    Bar
}

println(Bar)

And we get an error:

OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method java.util.ResourceBundle.setParent(java.util.ResourceBundle)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
/tmp/tmp16041171746066319857.tmp/scriptlet.803d758a4961398c.kts:1:8: error: unresolved reference: Repro
import Repro.Foo.Bar
       ^
/tmp/tmp16041171746066319857.tmp/scriptlet.803d758a4961398c.kts:11:9: error: unresolved reference: Bar
println(Bar)
        ^

Reproduces with and without content in shared.kt, and also with comment include directive.
Also reproduces with other nested constructs such as inner classes:

sealed class Foo {
    object Bar: Foo()
}

Does not reproduce with IDEA, which runs the files just fine (and created the import statement for me, in face). Therefore, I suspect a bug in kscript.


Real-life example: link


Version : v3.0.2
Kotlin : 1.4.21-release-351
Java : JRE 14.0.2+12)

Reproduces with JRE 11 as well.
@reitzig
Copy link
Author

reitzig commented Dec 13, 2020

Ah. The problem is the file name of the aggregate file, isn't it? kscript would either have to use the original file names, or rewrite the imports. 🤔

@holgerbrandl
Copy link
Collaborator

It indeed assumed to the included file to be in the same package. It partially rewrites the imports to show up on top of the merged script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants