Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sweet-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • sweet-js
  • sweet-core
  • Issues
  • #729
Closed
Open
Issue created Jun 21, 2017 by Administrator@rootContributor

Unable to compile operator

Created by: Jamesernator

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.

Assignee
Assign to
Time tracking