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

Type Tests for Negation Types #8

Open
DavePearce opened this issue Nov 5, 2016 · 0 comments
Open

Type Tests for Negation Types #8

DavePearce opened this issue Nov 5, 2016 · 0 comments
Labels

Comments

@DavePearce
Copy link
Member

The following from TypeEquals_Valid_57 fails at JVM verification time:

type nat is (int x) where x >= 0

function f(int|null x) -> nat:
    //
    if x is !nat:
        return 0
    else:
        return x

The reason is not completely clear. The bytecode looks like this:

         0: aload_0
         1: getstatic     #22                 // Field constant$1:Lwyjc/runtime/WyType;
         4: swap
         5: invokevirtual #12                 // Method wyjc/runtime/WyType.is:(Ljava/lang/Object;)Lwyjc/runtime/WyBool;
         8: invokevirtual #34                 // Method wyjc/runtime/WyBool.value:()Z
        11: ifne          22
        14: aload_0
        15: checkcast     #28                 // class java/math/BigInteger
        18: astore_0
        19: goto          41
        22: aload_0
        23: astore_0
        24: aload_0
        25: invokestatic  #31                 // Method nat$typeof:(Ljava/math/BigInteger;)Z
        28: ifeq          34
        31: goto          14
        34: getstatic     #1                  // Field constant$0:Ljava/math/BigInteger;
        37: areturn
        38: goto          43
        41: aload_0
        42: areturn
        43: return

The problem is that, on the true branch, it needs to perform a checkcast before calling nat$typeof(). For some reason it's not doing that. The type test being used should be against !int. So, on the true branch, it shouldn't need to check the invariant. In fact, it should be checking the invariant on the false branch and, if the invariant doesn't hold, branching back to the true branch.

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

No branches or pull requests

1 participant