-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use float equality for AST comparisons (#1238)
## Summary Float equality lacks the substitution nor reflexivity properties usually expected from an equality operator, so it's not correct to use float equality in AST comparisons. This PR changes it so that they are compared for bit equality. ## Details * `0.0` and `-0.0` are not being considered equal by the compiler anymore, this affects: - static parameters in generic types and procedures, see `tests/statictypes/tstatictypes.nim` - default arguments for forward declarations, see `tests/errmsgs/tforwarddecl_defaultparam.nim` - ```macros.`==`(a, b: NimNode)```, see `tests/lang_callable/macros/tmacros_various.nim` - term-rewriting macros, see `tests/lang_experimental/trmacros/trmacros_various2.nim` * `trees.exprStructuralEquivalentStrictSym` and it's only usage in `sem/semfoldnim` have been removed --------- Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
10 changed files
with
68 additions
and
52 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
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
discard """ | ||
errormsg: "overloaded 'reciprocal' leads to ambiguous calls" | ||
line: 9 | ||
""" | ||
|
||
# Differing float literal default args must prevent forward declaration | ||
# and the compiler must not compare them via float equality | ||
proc reciprocal(f: float = 0.0): float | ||
proc reciprocal(f: float = -0.0): float = 1 / f |
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
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