Skip to content

Access After Clone #15

Description

@DavePearce

The following fails:

public export method test() :
    {bool flag, int code} x = {flag: true, code: 0}
    if x.flag:
        assert true
    else:
        assert false

This generates the following Java:

import java.math.BigInteger;
import java.util.Arrays;
import java.util.function.Function;
public final class BoolRecord_Valid_2 {
	public static void test() {
		Struct0 x = new Struct0(true, BigInteger.valueOf(0L));
		if(x.clone().flag)  {
			assert true;
		} else  {
			assert false;
		}
	}
	static class Struct0 {
		boolean flag;
		BigInteger code;

		...

		public Object clone() {
			return new Struct0(flag, code);
		}
	}
}

The problem is that clone() returns object, rather than Struct0. Alternatively, the problem is that we shouldn't be cloning at this point anyway.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions