-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36ae73b
commit 2cdd92e
Showing
4 changed files
with
42 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,31 @@ OperatorDecl: class extends Expression { | |
} | ||
} | ||
|
||
if (symbol != "as") { | ||
numArgs := fDecl args size | ||
if (fDecl owner) { | ||
numArgs += 1 | ||
} | ||
|
||
if(numArgs != 2) { | ||
match (symbol) { | ||
case "-" || "+" => | ||
if (numArgs != 1) { | ||
res throwError(InvalidOperatorOverload new(token, | ||
"Overloading '%s' requires 1 or 2 arguments, not %d" format(symbol, numArgs))) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fasterthanlime
Author
Collaborator
|
||
} | ||
case "[]=" => | ||
if (numArgs != 3) { | ||
res throwError(InvalidOperatorOverload new(token, | ||
"Overloading '%s' requires 3 arguments, not %d" format(symbol, numArgs))) | ||
} | ||
case => | ||
res throwError(InvalidOperatorOverload new(token, | ||
"Overloading '%s' requires 2 arguments, not %d" format(symbol, numArgs))) | ||
} | ||
} | ||
} | ||
|
||
Response OK | ||
} | ||
|
||
|
@@ -164,6 +189,7 @@ InvalidOperatorOverload: class extends Error { | |
init: super func ~tokenMessage | ||
} | ||
|
||
|
||
OverloadStatus: enum { | ||
TRYAGAIN // operator usage waiting for something else to resolve | ||
REPLACED // operator usage was replaced with a call to an overload | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
//! shouldfail | ||
|
||
Vec2: class { | ||
x, y: Int | ||
|
||
operator * -> This { | ||
this | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
|
||
use sam-assert | ||
|
||
Point2D: class { | ||
x, y: Int | ||
init: func(=x, =y) | ||
|
1 or 2?