mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
compiler: correctly generate code for local named types
It is possible to create function-local named types:
func foo() any {
type named int
return named(0)
}
This patch makes sure they don't alias with named types declared at the
package scope.
Bug originally found by Damian Gryski while working on reflect support.
This commit is contained in:
committed by
Ron Evans
parent
17f5fb1071
commit
523c6c0e3b
Vendored
+35
@@ -93,6 +93,12 @@ func main() {
|
||||
a int
|
||||
b int
|
||||
}{3, 6}},
|
||||
{true, named1(), named1()},
|
||||
{true, named2(), named2()},
|
||||
{false, named1(), named2()},
|
||||
{false, named2(), named3()},
|
||||
{true, namedptr1(), namedptr1()},
|
||||
{false, namedptr1(), namedptr2()},
|
||||
}
|
||||
for i, tc := range interfaceEqualTests {
|
||||
if (tc.lhs == tc.rhs) != tc.equal {
|
||||
@@ -277,3 +283,32 @@ func (f FooByte) Byte() byte { return byte(f) }
|
||||
type Byter interface {
|
||||
Byte() uint8
|
||||
}
|
||||
|
||||
// Make sure that named types inside functions do not alias with any other named
|
||||
// functions.
|
||||
|
||||
type named int
|
||||
|
||||
func named1() any {
|
||||
return named(0)
|
||||
}
|
||||
|
||||
func named2() any {
|
||||
type named int
|
||||
return named(0)
|
||||
}
|
||||
|
||||
func named3() any {
|
||||
type named int
|
||||
return named(0)
|
||||
}
|
||||
|
||||
func namedptr1() interface{} {
|
||||
type Test int
|
||||
return (*Test)(nil)
|
||||
}
|
||||
|
||||
func namedptr2() interface{} {
|
||||
type Test byte
|
||||
return (*Test)(nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user