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

_run_kt_java_builder_actions references unassigned java_info variable #877

Closed
barm opened this issue Dec 2, 2022 · 1 comment · Fixed by #915
Closed

_run_kt_java_builder_actions references unassigned java_info variable #877

barm opened this issue Dec 2, 2022 · 1 comment · Fixed by #915

Comments

@barm
Copy link

barm commented Dec 2, 2022

Found this issue while attempting to upgrade from 1.5 to 1.6. If there are annotation processors, we try to access java_info which is not assigned:

Traceback (most recent call last):
	File "/private/var/tmp/_bazel_brian/543db2c15cef85941ff9c139e2f8f864/external/io_bazel_rules_kotlin/kotlin/internal/jvm/impl.bzl", line 259, column 44, in kt_jvm_junit_test_impl
		providers = _kt_jvm_produce_jar_actions(ctx, "kt_jvm_test")
	File "/private/var/tmp/_bazel_brian/543db2c15cef85941ff9c139e2f8f864/external/io_bazel_rules_kotlin/kotlin/internal/jvm/compile.bzl", line 491, column 50, in kt_jvm_produce_jar_actions
		outputs_struct = _run_kt_java_builder_actions(
	File "/private/var/tmp/_bazel_brian/543db2c15cef85941ff9c139e2f8f864/external/io_bazel_rules_kotlin/kotlin/internal/jvm/compile.bzl", line 746, column 56, in _run_kt_java_builder_actions
		ap_class_jar = [jars.class_jar for jars in java_info.outputs.jars][0],
Error: local variable 'java_info' is referenced before assignment.
@barm barm changed the title _run_kt_java_builder_actions references unassigned java_info variable _run_kt_java_builder_actions references unassigned java_info variable Dec 2, 2022
@restingbull restingbull self-assigned this Dec 2, 2022
@barm
Copy link
Author

barm commented Dec 2, 2022

Just wanted to add a note: I haven't created a minimal project reproducing this yet but I did read the code and I can't find an assignment before it's used. If you need a minimal reproducing project I can look into that as well.

avarun42 added a commit to avarun42/rules_kotlin that referenced this issue Jan 13, 2023
`compile.bzl` was incorrectly referencing `java_info` instead of `java_infos` in cases where annotation processors were found, causing compilation to fail with an opaque error (bazelbuild#877). This fixes the reference.
restingbull pushed a commit that referenced this issue Jan 13, 2023
* Fix reference to java_infos in compile.bzl

`compile.bzl` was incorrectly referencing `java_info` instead of `java_infos` in cases where annotation processors were found, causing compilation to fail with an opaque error (#877). This fixes the reference.

* Replace incorrect property access on list with list comprehension

Fixing the typo resulted in the following error:

```
Traceback (most recent call last):
	File "/workdir/kotlin/internal/jvm/impl.bzl", line 219, column 36, in kt_jvm_library_impl
		_kt_jvm_produce_jar_actions(ctx, "kt_jvm_library") if ctx.attr.srcs or ctx.attr.resources else export_only_providers(
	File "/workdir/kotlin/internal/jvm/compile.bzl", line 493, column 50, in kt_jvm_produce_jar_actions
		outputs_struct = _run_kt_java_builder_actions(
	File "/workdir/kotlin/internal/jvm/compile.bzl", line 751, column 66, in _run_kt_java_builder_actions
		ap_class_jar = [jars.class_jar for jars in java_infos.outputs.jars][0],
Error: 'list' value has no field or method 'outputs'
```

`java_infos` is a list and thus doesn't have an `outputs` field, but each `java_info` inside the list does. Thus replacing `java_infos.outputs.jars` with the list comprehension `[java_info.outputs.jars for java_info in java_infos]` gets us a list of `jars` objects that can be used in the outer list comprehension.

* extract out inner list comprehension

* flatten list of jars lists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants