Repeating a field name in a type results in miscompilation
ColonelPhantom opened this issue · comments
Reproducing the behavior
With the code
type Expr
= (Lit Int)
| (Plus Expr Expr)
eval (Expr/Lit i) = i
eval (Expr/Plus l r) = (+ (eval l) (eval r))
main = (eval (Expr/Plus (Expr/Lit 80) (Expr/Lit 90)))
running it with at least both run
and run-c
gives the wrong result of 180, rather than 170.
Without eval
, Bend also seems to print something like (+ 90 90)
rather than (+ 80 90)
System Settings
- hvm 2.0.19
- bend-lang 0.2.33
- OS: Linux
- CPU: i5-8350U
Additional context
Could this be related to unsafe dup-ing? I thought that that would only affect unrealistic program, not this very simple one.
This is happening because the Plus
constructor has both fields with the same name Expr
(the names inside constructors are field names, not types), so bend miscompiles it.
As a fix, before the compiler catches this problem and suggest this itself, you can name then (Plus left right)
, or any other names you would prefer.
At some point in the past the compiler checked for repeated field names, but it seems I accidentally removed it.