-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: improve field and method resolution in presence of collisions.
The resolution method was not compliant with the Go specification which requires to retain the object where the field or method is the most shallowed. The detection of ambiguous fields or methods (same depth in different objects) has also been added. Fixes #1163.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 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,41 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type WidgetEvent struct { | ||
Nothing string | ||
} | ||
|
||
type WidgetControl interface { | ||
HandleEvent(e *WidgetEvent) | ||
} | ||
|
||
type Button struct{} | ||
|
||
func (b *Button) HandleEvent(e *WidgetEvent) { | ||
} | ||
|
||
type WindowEvent struct { | ||
Something int | ||
} | ||
|
||
type Window struct { | ||
Widget WidgetControl | ||
} | ||
|
||
func (w *Window) HandleEvent(e *WindowEvent) { | ||
} | ||
|
||
func main() { | ||
window := &Window{ | ||
Widget: &Button{}, | ||
} | ||
windowevent := &WindowEvent{} | ||
// The next line uses the signature from the wrong method, resulting in an error. | ||
// Renaming one of the clashing method names fixes the problem. | ||
window.HandleEvent(windowevent) | ||
fmt.Println("OK!") | ||
} | ||
|
||
// Output: | ||
// OK! |
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