Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Jun 18, 2024
1 parent 4292a3f commit 2f5b613
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
40 changes: 25 additions & 15 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,18 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
if isUntyped(rt) { // e.g. int(1) + 1<<x
checkOrConvertType(store, last, &n.Right, lt, false)
} else { // both typed, left typed const, right typed non-const
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in binary expression: %v %v %v",
lt.TypeID(), n.Op, rt.TypeID()))
if !shouldSwapOnSpecificity(lt, rt) {
checkOrConvertType(store, last, &n.Left, rt, false)
} else {
checkOrConvertType(store, last, &n.Right, lt, false)
}
/*
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in XXX binary expression: %v %v %v",
lt.TypeID(), n.Op, rt.TypeID()))
}
*/
}
}
} else if ric { // right is const, left is not
Expand Down Expand Up @@ -894,11 +901,18 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
if isUntyped(lt) {
checkOrConvertType(store, last, &n.Left, rt, false)
} else {
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in binary expression: %v %v %v",
lt.TypeID(), n.Op, rt.TypeID()))
if !shouldSwapOnSpecificity(lt, rt) {
checkOrConvertType(store, last, &n.Left, rt, false)
} else {
checkOrConvertType(store, last, &n.Right, lt, false)
}
/*
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in XXX binary expression: %v %v %v",
lt.TypeID(), n.Op, rt.TypeID()))
}
*/
}
}
} else { // ---both not const---
Expand Down Expand Up @@ -1002,14 +1016,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
} else if riu { // left typed, right untyped
checkOrConvertType(store, last, &n.Right, lt, false)
} else { // both typed, refer to 0a1g.gno
if n.Op == EQL || n.Op == NEQ {
// nothing to do
if !shouldSwapOnSpecificity(lt, rt) {
checkOrConvertType(store, last, &n.Left, rt, false)
} else {
if !shouldSwapOnSpecificity(lt, rt) {
checkOrConvertType(store, last, &n.Left, rt, false)
} else {
checkOrConvertType(store, last, &n.Right, lt, false)
}
checkOrConvertType(store, last, &n.Right, lt, false)
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion gnovm/tests/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,12 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
errstr = parts[0]
}
if errstr != errWanted {
panic(fmt.Sprintf("fail on %s: got %q, want: %q", path, errstr, errWanted))
if f.syncWanted {
// write error to file
replaceWantedInPlace(path, "Error", errstr)
} else {
panic(fmt.Sprintf("fail on %s: got %q, want: %q", path, errstr, errWanted))
}
}

// NOTE: ignores any gno.GetDebugErrors().
Expand All @@ -293,6 +298,7 @@ func RunFileTest(rootDir string, path string, opts ...RunFileTestOption) error {
ctl := errstr +
"\n*** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, " +
"DELETE THIS LINE AND RUN TEST AGAIN ***"
// write error to file
replaceWantedInPlace(path, "Error", ctl)
panic(fmt.Sprintf("fail on %s: err recorded, check the message and run test again", path))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ func main() {
}

// Error:
// main/files/assign_unnamed_type/method/declaredType6b_filetest.gno:15: cannot use uint as main.word without explicit conversion
// main/files/assign_unnamed_type/method/declaredType6b_filetest.gno:15: cannot use []uint as []main.word
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Error:
// main/files/assign_unnamed_type/unnamedtype0b_filetest.gno:11: cannot use main.word as int without explicit conversion
// main/files/assign_unnamed_type/unnamedtype0b_filetest.gno:11: cannot use []main.word as []int
2 changes: 1 addition & 1 deletion gnovm/tests/files/types/eql_0a1a1.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ func main() {
}

// Error:
// main/files/types/eql_0a1a1.gno:5: cannot use uint64 as uint
// main/files/types/eql_0a1a1.gno:5: cannot use uint as uint64
2 changes: 1 addition & 1 deletion gnovm/tests/files/types/eql_0f14.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ func main() {
}

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

0 comments on commit 2f5b613

Please sign in to comment.