Skip to content

Commit 2f5b613

Browse files
committed
...
1 parent 4292a3f commit 2f5b613

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

gnovm/pkg/gnolang/preprocess.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,18 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
847847
if isUntyped(rt) { // e.g. int(1) + 1<<x
848848
checkOrConvertType(store, last, &n.Right, lt, false)
849849
} else { // both typed, left typed const, right typed non-const
850-
if lt.TypeID() != rt.TypeID() {
851-
panic(fmt.Sprintf(
852-
"incompatible types in binary expression: %v %v %v",
853-
lt.TypeID(), n.Op, rt.TypeID()))
850+
if !shouldSwapOnSpecificity(lt, rt) {
851+
checkOrConvertType(store, last, &n.Left, rt, false)
852+
} else {
853+
checkOrConvertType(store, last, &n.Right, lt, false)
854854
}
855+
/*
856+
if lt.TypeID() != rt.TypeID() {
857+
panic(fmt.Sprintf(
858+
"incompatible types in XXX binary expression: %v %v %v",
859+
lt.TypeID(), n.Op, rt.TypeID()))
860+
}
861+
*/
855862
}
856863
}
857864
} else if ric { // right is const, left is not
@@ -894,11 +901,18 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
894901
if isUntyped(lt) {
895902
checkOrConvertType(store, last, &n.Left, rt, false)
896903
} else {
897-
if lt.TypeID() != rt.TypeID() {
898-
panic(fmt.Sprintf(
899-
"incompatible types in binary expression: %v %v %v",
900-
lt.TypeID(), n.Op, rt.TypeID()))
904+
if !shouldSwapOnSpecificity(lt, rt) {
905+
checkOrConvertType(store, last, &n.Left, rt, false)
906+
} else {
907+
checkOrConvertType(store, last, &n.Right, lt, false)
901908
}
909+
/*
910+
if lt.TypeID() != rt.TypeID() {
911+
panic(fmt.Sprintf(
912+
"incompatible types in XXX binary expression: %v %v %v",
913+
lt.TypeID(), n.Op, rt.TypeID()))
914+
}
915+
*/
902916
}
903917
}
904918
} else { // ---both not const---
@@ -1002,14 +1016,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
10021016
} else if riu { // left typed, right untyped
10031017
checkOrConvertType(store, last, &n.Right, lt, false)
10041018
} else { // both typed, refer to 0a1g.gno
1005-
if n.Op == EQL || n.Op == NEQ {
1006-
// nothing to do
1019+
if !shouldSwapOnSpecificity(lt, rt) {
1020+
checkOrConvertType(store, last, &n.Left, rt, false)
10071021
} else {
1008-
if !shouldSwapOnSpecificity(lt, rt) {
1009-
checkOrConvertType(store, last, &n.Left, rt, false)
1010-
} else {
1011-
checkOrConvertType(store, last, &n.Right, lt, false)
1012-
}
1022+
checkOrConvertType(store, last, &n.Right, lt, false)
10131023
}
10141024
}
10151025
}

gnovm/tests/file.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,12 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
269269
errstr = parts[0]
270270
}
271271
if errstr != errWanted {
272-
panic(fmt.Sprintf("fail on %s: got %q, want: %q", path, errstr, errWanted))
272+
if f.syncWanted {
273+
// write error to file
274+
replaceWantedInPlace(path, "Error", errstr)
275+
} else {
276+
panic(fmt.Sprintf("fail on %s: got %q, want: %q", path, errstr, errWanted))
277+
}
273278
}
274279

275280
// NOTE: ignores any gno.GetDebugErrors().
@@ -293,6 +298,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
293298
ctl := errstr +
294299
"\n*** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, " +
295300
"DELETE THIS LINE AND RUN TEST AGAIN ***"
301+
// write error to file
296302
replaceWantedInPlace(path, "Error", ctl)
297303
panic(fmt.Sprintf("fail on %s: err recorded, check the message and run test again", path))
298304
}

gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ func main() {
1717
}
1818

1919
// Error:
20-
// main/files/assign_unnamed_type/method/declaredType6b_filetest.gno:15: cannot use uint as main.word without explicit conversion
20+
// main/files/assign_unnamed_type/method/declaredType6b_filetest.gno:15: cannot use []uint as []main.word

gnovm/tests/files/assign_unnamed_type/unnamedtype0b_filetest.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ func main() {
1414
}
1515

1616
// Error:
17-
// main/files/assign_unnamed_type/unnamedtype0b_filetest.gno:11: cannot use main.word as int without explicit conversion
17+
// main/files/assign_unnamed_type/unnamedtype0b_filetest.gno:11: cannot use []main.word as []int

gnovm/tests/files/types/eql_0a1a1.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ func main() {
66
}
77

88
// Error:
9-
// main/files/types/eql_0a1a1.gno:5: cannot use uint64 as uint
9+
// main/files/types/eql_0a1a1.gno:5: cannot use uint as uint64

gnovm/tests/files/types/eql_0f14.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ func main() {
1111
}
1212

1313
// Error:
14-
// main/files/types/eql_0f14.gno:10: cannot use string as int
14+
// main/files/types/eql_0f14.gno:10: cannot use [2]string as [2]int

0 commit comments

Comments
 (0)