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

Unable to compile operator #729

Open
Jamesernator opened this issue Jun 21, 2017 · 1 comment
Open

Unable to compile operator #729

Jamesernator opened this issue Jun 21, 2017 · 1 comment

Comments

@Jamesernator
Copy link

Jamesernator commented Jun 21, 2017

Using the latest version (3.0.10) this results in an error:

Number.prototype[Symbol.add] = new Function('other', 'return this + other')
Symbol.add = Symbol('add')

operator + left 13 = (left, right) => {
    return #`(${ left })[Symbol.add](${ right })`
}

class Point {
    constructor(x, y) {
        this.x = x
        this.y = y
    }

    [Symbol.add](other) {
        return new Point(this.x + other.x, this.y + other.y)
    }
}

const x = new Point(3,4) + new Point(5,6)
Error message Error: Unknown object: {"value":{"token":{"typeCode":3,"type":{"klass":{"name":"Numeric"},"name":""},"value":3,"slice":{"text":"3","start":397,"startLocation":{"line":20,"column":21,"filename":"","position":397},"end":398},"octal":false,"noctal":false},"bindings":{"_map":{}},"scopesets":{"all":[{"name":"outsideEdge_1"}],"phase":{"0":[{"name":"insideEdge0_2"}]}}},"type":"RawSyntax","loc":null}

I'm not sure what the minimal cause of the bug is, but I did find that if I do:

const x = (new Point(3,4)) + (new Point(5,6))

// Or something like
function Point(x, y) {
    return {
        x, y,
        [Symbol.add](other) {
            return Point(this.x + other.x, this.y + other.y)
        }
    }
}

const x = Point(3, 4) + Point(4,5)

Then it's happy.

So it's probably some interaction between operator overloading and new.

@disnet
Copy link
Member

disnet commented Jun 22, 2017

I just ran into a potentially similar problem with new:

let f = x => new C(x)

throws an error but

let f = x => { return new C(x); }

does not. Might be unrelated but I suspect it has something to do with how we parse new.

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

No branches or pull requests

2 participants