frgaal icon indicating copy to clipboard operation
frgaal copied to clipboard

Frgaal fails to recognize records during separate compilation

Open hubertp opened this issue 2 years ago • 1 comments

Consider the following setup.

> cat Base.java 
public interface Base {
    static Base foo() {
	return new Foo();
    }
}

> cat Foo.java 
public record Foo() implements Base {
}

> cat Main.java 
class Main {
    public static void main(String[] args) {
        var x = Base.foo();
	switch (x) {
		case Foo() -> System.out.println("OK.");
	        default    -> System.out.println("Not OK.");
	}
    }

}

If you compile all files with Frgaal at once everything is fine:

java -jar compiler-20.0.0.jar --enable-preview --source 20 -d target *.java
Note: Main.java uses preview features of Java SE 20.
Note: Recompile with -Xlint:preview for details.

But if you only compile files that changed:

java -jar compiler-20.0.0.jar --enable-preview --source 20 -d target -cp target Main.java
Main.java:5: error: deconstruction patterns can only be applied to records, Foo is not a record
		case Foo() -> System.out.println("OK.");
		     ^
Note: Main.java uses preview features of Java SE 20.
Note: Recompile with -Xlint:preview for details.
1 error

This is not a theoretical scenario. Separate compilation is present in build tools like sbt, to speed up compilation times for large projects.

hubertp avatar Apr 28 '23 13:04 hubertp

The failure is real and happens from time to time in our CI.

JaroslavTulach avatar May 18 '23 06:05 JaroslavTulach