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

Switching to Java 19 Frgaal compiler #3594

Merged
merged 2 commits into from
Jul 19, 2022

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Jul 16, 2022

[ci no changelog needed]

Pull Request Description

Updating to Frgaal 19.0.0-RC1 to give us access to latest Java features including pattern matching on record classes. Builds upon #3421.

@JaroslavTulach
Copy link
Member Author

With the Frgaal 19.0.0-RC1 I am able to write code like:

import java.nio.ByteBuffer;


public sealed interface Expr permits Expr.Rec, Expr.Int, Expr.Numeric, LocationFakeExpr {
    public record Int(int value) implements Expr {
    }

    public record Numeric(double value) implements Expr {
    }

    public record Rec(Expr x, Expr y) implements Expr {
        public Rec {
            if (y != null) {
                throw new IllegalStateException("Don't specify y!");
            }
            if (x instanceof LocationFakeExpr) {
                
            } else {
                throw new IllegalStateException("Provide LocationFakeExpr as x!");
            }
        }

        private LocationFakeExpr at() {
            return (LocationFakeExpr) this.x;
        }

        public Expr x() {
            return new Int(at().b().getInt(at().o()));
        }

        public Expr y() {
            return new Int(at().b().getInt(at().o() + 4));
        }
    }
    
    public static void main(String... args) {
        ByteBuffer bb = ByteBuffer.allocateDirect(10);
        bb.putInt(0, 10);
        bb.putInt(4, 20);
        
        Expr r = new Rec(new LocationFakeExpr(bb, 0), null);
        
        switch (r) {
            case Rec(Numeric x, Int y) -> {
                System.err.println("num found: " + x + " and " + y);
            }
            case Rec(Int x, Int y) -> {
                System.err.println("ints found: " + x.value() + " and " + y.value());
            }
            default ->
                System.err.println("not found: " + r);
        }
    }
}

record LocationFakeExpr(ByteBuffer b, int o) implements Expr {
}

@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label Jul 16, 2022
@JaroslavTulach JaroslavTulach force-pushed the wip/jtulach/AllowJava19_181988063 branch from 578397b to 973ebc1 Compare July 18, 2022 11:17
@mergify mergify bot merged commit 030e46b into develop Jul 19, 2022
@mergify mergify bot deleted the wip/jtulach/AllowJava19_181988063 branch July 19, 2022 09:28
jdunkerley pushed a commit that referenced this pull request Jul 20, 2022
Updating to Frgaal 19.0.0-RC1 to give us access to latest Java features including pattern matching on `record` classes. Builds upon #3421.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants