Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): handle type alias declaration for PrimitiveType #3222

7 changes: 4 additions & 3 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,10 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
// }
*dst = *dt2
}
case PrimitiveType:
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
dst = tmp.(PrimitiveType)
case *PointerType:
*dst = *(tmp.(*PointerType))
default:
panic(fmt.Sprintf("unexpected type declaration type %v",
reflect.TypeOf(dst)))
Expand Down Expand Up @@ -4283,9 +4287,6 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) {
// predefineNow preprocessed dependent types.
panic("should not happen")
}
} else {
// all names are declared types.
panic("should not happen")
}
} else if idx, ok := UverseNode().GetLocalIndex(tx.Name); ok {
// uverse name
Expand Down
46 changes: 46 additions & 0 deletions gnovm/tests/files/type40.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

type (
// PrimitiveType
Number = int32
Number2 = Number

// PointerType
Pointer = *int32
Pointer2 = Pointer

// Interface
Interface = interface{}
Interface2 = Interface

// S
Struct = struct{Name string}
Struct2 = Struct
)

func fNumber(n Number) { println(n) }
func fPointer(p Pointer) { println(*p) }
func fInterface(i Interface) { println(i) }
func fStruct(s Struct) { println(s.Name) }

func main() {
var n Number2 = 5
fNumber(n)

var num int32 = 6
var p Pointer2 = &num
fPointer(p)

var i Interface2
i = 7
fInterface(i)

var s Struct2 = Struct2{Name: "yo"}
fStruct(s)
}

// Output:
// 5
// 6
// 7
// yo
Loading