-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct typed-nil handling (#1891)
update: ready for review. ==================================== the dependency relationship: #1890 <- this one. --------- Co-authored-by: Morgan Bazalgette <[email protected]>
- Loading branch information
1 parent
0a3df04
commit 64ea826
Showing
10 changed files
with
147 additions
and
2 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
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,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,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) |
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,18 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type integer int | ||
|
||
func main() { | ||
// illegal conversion | ||
// should not work | ||
if integer(nil) == nil { | ||
fmt.Println("integer is nil") | ||
} else { | ||
fmt.Println("integer is not nil") | ||
} | ||
} | ||
|
||
// Error: | ||
// main/files/types/typed_nil_a.gno:10:5: cannot convert (const (undefined)) to IntKind |
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,16 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type integer *int | ||
|
||
func main() { | ||
println(integer(nil)) | ||
fmt.Println(integer(nil)) | ||
fmt.Printf("%T\n", integer(nil)) | ||
} | ||
|
||
// Output: | ||
// (nil main.integer) | ||
// <nil> | ||
// *int |
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 "fmt" | ||
|
||
func main() { | ||
println(interface{}(nil) == (*int)(nil)) | ||
fmt.Printf("%T\n", interface{}(nil)) | ||
} | ||
|
||
// Output: | ||
// false | ||
// <nil> |