bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Turbine crashes on certain `sealed` usages

Open fmeum opened this issue 10 months ago • 4 comments

Description of the bug:

Turbine fails when using sealed with permits on a generated class:

java.lang.AssertionError: ERROR_TY
	at com.google.turbine.binder.TypeBinder.bind(TypeBinder.java:239)
	at com.google.turbine.binder.TypeBinder.bind(TypeBinder.java:149)
	at com.google.turbine.binder.Binder.bindTypes(Binder.java:319)
	at com.google.turbine.binder.Binder.bind(Binder.java:168)
	at com.google.turbine.binder.Binder.bind(Binder.java:110)
	at com.google.turbine.binder.Binder.bind(Binder.java:94)
	at com.google.turbine.main.Main.bind(Main.java:270)
	at com.google.turbine.main.Main.compile(Main.java:158)
	at com.google.turbine.main.Main.compile(Main.java:133)
	at com.google.turbine.main.Main.main(Main.java:89)
	at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

Which category does this issue belong to?

Java Rules

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. Check out Bazel at 45836d025b.
  2. Apply this patch:
git diff src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileValue.java
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileValue.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileValue.java
index 7c7e38fd6c..bf8e2a10a5 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileValue.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileValue.java
@@ -27,7 +27,7 @@ import com.google.devtools.build.skyframe.SkyValue;
 import javax.annotation.Nullable;

 /** The result of {@link ModuleFileFunction}. */
-public abstract class ModuleFileValue implements SkyValue {
+public abstract sealed class ModuleFileValue implements SkyValue {

   public static final ModuleFileValue.Key KEY_FOR_ROOT_MODULE = key(ModuleKey.ROOT, null);

@@ -43,7 +43,8 @@ public abstract class ModuleFileValue implements SkyValue {

   /** The {@link ModuleFileValue} for non-root modules. */
   @AutoValue
-  public abstract static class NonRootModuleFileValue extends ModuleFileValue {
+  public abstract static sealed class NonRootModuleFileValue extends ModuleFileValue
+      permits AutoValue_ModuleFileValue_NonRootModuleFileValue {

     public static NonRootModuleFileValue create(InterimModule module, String moduleFileHash) {
       return new AutoValue_ModuleFileValue_NonRootModuleFileValue(module, moduleFileHash);
@@ -55,7 +56,8 @@ public abstract class ModuleFileValue implements SkyValue {
    * overrides.
    */
   @AutoValue
-  public abstract static class RootModuleFileValue extends ModuleFileValue {
+  public abstract static sealed class RootModuleFileValue extends ModuleFileValue
+      permits AutoValue_ModuleFileValue_RootModuleFileValue {
     /**
      * The overrides specified by the evaluated module file. The key is the module name and the
      * value is the override itself.
  1. Attempt to build //src:bazel-dev.

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

fmeum avatar Apr 24 '24 19:04 fmeum

cc @cushon

fmeum avatar Apr 24 '24 19:04 fmeum

Thanks for the report! That's already fixed in https://github.com/google/turbine/commit/468742ff49d1881bf4822bb9d0d820105b28dba8, I'm working on releasing a new version and updating Bazel's dependency on turbine.

cushon avatar Apr 24 '24 19:04 cushon

Turbine got released and updated in https://github.com/bazelbuild/bazel/commit/81117aabe22f615743a2fe01548f9764dcad8a63

Can we close this, or is there something else we need to wait for?

hvadehra avatar May 08 '24 12:05 hvadehra

@hvadehra I think that we need to have a new java_tools and rules_java release + bump in bazel_tools dependencies for this to be considered "done".

fmeum avatar May 08 '24 12:05 fmeum