-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: fix a panic when embedding an error interface
This patch brings the following modifications: - consider that an interface is assignable to another if the former implements the latter - call TypeOf() method instead of rtype field when resolving methods, to handle first met types - unwrap error interface inplace rather than embedding it in an interface definition, as lower case named embbeded interface may not be handled by reflect when lookup for a method. Fixes #1063. Partially improves #1058.
- Loading branch information
Showing
2 changed files
with
47 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
type Error interface { | ||
error | ||
Message() string | ||
} | ||
|
||
type T struct { | ||
Msg string | ||
} | ||
|
||
func (t *T) Error() string { return t.Msg } | ||
func (t *T) Message() string { return "message:" + t.Msg } | ||
|
||
func newError() Error { return &T{"test"} } | ||
|
||
func main() { | ||
e := newError() | ||
println(e.Error()) | ||
} | ||
|
||
// Output: | ||
// test |
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