implementing user defined operators - #535
Conversation
dfec27a to
983de64
Compare
6a48e50 to
423f5ae
Compare
|
So this could implement |
Could you give an example of using this operator? |
|
They are units in Solidity: https://docs.soliditylang.org/en/v0.8.36/units-and-global-variables.html#ether-units So |
Thanks! It is now implemented. |
|
Awesome, so flexible! These units in classic are a painful exception in the parser 😅 |
| pragma no-patterson-condition ABIEncode, Num, Array, ArrayPush, Eq, Ord; | ||
| pragma no-coverage-condition ABIDecode, MemoryType, Array, ArrayPush, RValueIdxAccess; | ||
|
|
||
| // Built-in operators are defined here, not in the compiler. Each declaration |
There was a problem hiding this comment.
Since these are here -- can we remove the extra parsing stuff from Haskell?
There was a problem hiding this comment.
I believe that I removed these extra parsing stuff from the parsing modules.
There was a problem hiding this comment.
Yes, just looked at it properly.
Do wonder what happens in these cases:
- An operator is not defined, but we try a compound assignment for it.
- An operator is redefined.
- An operator is defined as infix and postfix, and other combinations.
Can we have tests for them?
0d0c62d to
cdb088c
Compare
| pragma no-bounded-variable-condition ; | ||
|
|
||
| infixl 50 (##) => binA; | ||
| infixl 60 (##) => binB; |
There was a problem hiding this comment.
I'd also add a test case for redefining at the same priority, to make sure none of the parsers make a lookup separation based on that.
There was a problem hiding this comment.
Added test cases for this.
| isOpChar :: Char -> Bool | ||
| isOpChar c = | ||
| c `elem` ("+-*/%<>=!&|^~#?" :: String) | ||
| || (c >= '\x2200' && c <= '\x23FF') |
There was a problem hiding this comment.
Since these special unicode code pages are allowed, there should be a test using it. Like 1 ∈ arr for finding a element 1 😅
I'm also a bit worried it may be misused, but lets see.
There was a problem hiding this comment.
Well, I could remove that. But, I think it improve readability if it is not overused.
There was a problem hiding this comment.
No I meant to at least add a test for it and the have it documented later. We can always revise.
|
@rodrigogribeiro opus said this, not sure if any of them are actual bugs: I'll start by exploring the solcore repo to find the user-defined-operators code. I couldn't build (no Bugs found1. The operator pre-scan reads comments and string literals —
|
mbenke
left a comment
There was a problem hiding this comment.
Operator imports are not working correctly, making it difficult to redefine operators:
ben@trawa:~/work/review$ cat tmp/udop.solc
import std.{addWord};
infixl 45 (+) => addWord;
contract Ops {
function main() -> word { 2 + 2 }
}ben@trawa:~/work/review$ esolc -f tmp/udop.solc -s -g
error[SC0101]: undefined name: Add.add
──> /home/ben/work/review/tmp/udop.solc:6:29
│
6 │ function main() -> word { 2 + 2 }
│ ^^^^^^ unknown name
note: in: return Add.add(2, 2) ;
note: in: function main () -> word {
return Add.add(2, 2) ;
}
note: in: contract Ops {
function main () -> word {
return Add.add(2, 2) ;
}
}
note: module validation failed for /home/ben/work/review/tmp/udop.solc
cd44a4e to
47e5a51
Compare
Thanks! I've fixed all these points (some were really tricky, due to the interaction with modules). |
No description provided.