mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
compiler: merge runtime.typecodeID and runtime.typeInInterface
This distinction was useful before when reflect wasn't properly supported. Back then it made sense to only include method sets that were actually used in an interface. But now that it is possible to get to other values (for example, by extracting fields from structs) and it is possible to turn them back into interfaces, it is necessary to preserve all method sets that can possibly be used in the program in a type assert, interface assert or interface method call. In the future, this logic will need to be revisited again when reflect.New or reflect.Zero gets implemented. Code size increases a bit in some cases, but usually in a very limited way (except for one outlier in the drivers smoke tests). The next commit will improve the situation significantly.
This commit is contained in:
committed by
Ron Evans
parent
aa7c7b7bd9
commit
bbb2909283
Vendored
+19
@@ -265,6 +265,19 @@ func main() {
|
||||
println("type assertion failed (but should succeed)")
|
||||
}
|
||||
|
||||
// Test type that is not referenced at all: not when creating the
|
||||
// reflect.Value (except through the field) and not with a type assert.
|
||||
// Previously this would result in a type assert failure because the Int()
|
||||
// method wasn't picked up.
|
||||
v = reflect.ValueOf(struct {
|
||||
X totallyUnreferencedType
|
||||
}{})
|
||||
if v.Field(0).Interface().(interface {
|
||||
Int() int
|
||||
}).Int() != 42 {
|
||||
println("could not call method on totally unreferenced type")
|
||||
}
|
||||
|
||||
if reflect.TypeOf(new(myint)) != reflect.PtrTo(reflect.TypeOf(myint(0))) {
|
||||
println("PtrTo failed for type myint")
|
||||
}
|
||||
@@ -363,6 +376,12 @@ func assertSize(ok bool, typ string) {
|
||||
|
||||
type unreferencedType int
|
||||
|
||||
type totallyUnreferencedType int
|
||||
|
||||
func (totallyUnreferencedType) Int() int {
|
||||
return 42
|
||||
}
|
||||
|
||||
func TestStructTag() {
|
||||
type S struct {
|
||||
F string `species:"gopher" color:"blue"`
|
||||
|
||||
Reference in New Issue
Block a user