forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): correct comparison between different types (gnolang#1890)
Fixes gnolang#1376, fixes gnolang#2386. --------- Co-authored-by: deelawn <[email protected]>
- Loading branch information
1 parent
1e0e52c
commit 8bd07c9
Showing
26 changed files
with
522 additions
and
33 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,12 @@ | ||
package main | ||
|
||
import "bytes" | ||
|
||
func main() { | ||
cmp := bytes.Compare([]byte("hello"), []byte("hey")) | ||
println(cmp) | ||
|
||
} | ||
|
||
// Output: | ||
// -1 |
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,27 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
) | ||
|
||
type Error int64 | ||
|
||
func (e Error) Error() string { | ||
return "error: " + strconv.Itoa(int(e)) | ||
} | ||
|
||
var errCmp = errors.New("XXXX") | ||
|
||
// special case: | ||
// one is interface | ||
func main() { | ||
if Error(0) == errCmp { | ||
println("what the firetruck?") | ||
} else { | ||
println("something else") | ||
} | ||
} | ||
|
||
// Output: | ||
// something else |
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,29 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
) | ||
|
||
type Error int64 | ||
|
||
func (e Error) Error() string { | ||
return "error: " + strconv.Itoa(int(e)) | ||
} | ||
|
||
// typed | ||
var errCmp error = errors.New("XXXX") | ||
|
||
// special case: | ||
// one is interface | ||
func main() { | ||
const e Error = Error(0) // typed const | ||
if e == errCmp { | ||
println("what the firetruck?") | ||
} else { | ||
println("something else") | ||
} | ||
} | ||
|
||
// Output: | ||
// something else |
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,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
type E interface { | ||
Error() string | ||
} | ||
type Error int64 | ||
|
||
func (e Error) Error() string { | ||
return "error: " + strconv.Itoa(int(e)) | ||
} | ||
|
||
// special case: | ||
// one is interface | ||
func main() { | ||
var e0 E | ||
e0 = Error(0) | ||
fmt.Printf("%T \n", e0) | ||
if e0 == Error(0) { | ||
println("what the firetruck?") | ||
} else { | ||
println("something else") | ||
} | ||
} | ||
|
||
// Output: | ||
// int64 | ||
// what the firetruck? |
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,27 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
) | ||
|
||
type Error int64 | ||
|
||
func (e Error) Error() string { | ||
return "error: " + strconv.Itoa(int(e)) | ||
} | ||
|
||
var errCmp = errors.New("XXXX") | ||
|
||
// special case: | ||
// one is interface | ||
func main() { | ||
if Error(1) == errCmp { | ||
println("what the firetruck?") | ||
} else { | ||
println("something else") | ||
} | ||
} | ||
|
||
// Output: | ||
// something else |
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,24 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
type Error int64 | ||
|
||
func (e Error) Error() string { | ||
return "error: " + strconv.Itoa(int(e)) | ||
} | ||
|
||
// both not const, and both interface | ||
func main() { | ||
var l interface{} | ||
if l == Error(0) { | ||
println("what the firetruck?") | ||
} else { | ||
println("something else") | ||
} | ||
} | ||
|
||
// Output: | ||
// something else |
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,27 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
) | ||
|
||
type Error int64 | ||
|
||
func (e Error) Error() string { | ||
return "error: " + strconv.Itoa(int(e)) | ||
} | ||
|
||
var errCmp = errors.New("XXXX") | ||
|
||
// special case: | ||
// one is interface | ||
func main() { | ||
if errCmp == int64(1) { | ||
println("what the firetruck?") | ||
} else { | ||
println("something else") | ||
} | ||
} | ||
|
||
// Error: | ||
// main/files/types/cmp_iface_5_stdlibs.gno:19:5: int64 does not implement .uverse.error (missing method Error) |
Oops, something went wrong.