Skip to content

Commit

Permalink
fix: handle type alias declaration for PrimitiveType
Browse files Browse the repository at this point in the history
  • Loading branch information
hthieu1110 committed Nov 27, 2024
1 parent c1ae90b commit 3524b0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,8 @@ func preprocess1(store Store, ctx BlockNode, n Node) Node {
// }
*dst = *dt2
}
case PrimitiveType:
dst = tmp.(PrimitiveType)
default:
panic(fmt.Sprintf("unexpected type declaration type %v",
reflect.TypeOf(dst)))
Expand Down Expand Up @@ -4283,6 +4285,8 @@ func tryPredefine(store Store, last BlockNode, d Decl) (un Name) {
// predefineNow preprocessed dependent types.
panic("should not happen")
}
} else if _, ok := t.(PrimitiveType); ok {
// if primitive type then do nothing
} else {
// all names are declared types.
panic("should not happen")
Expand Down
16 changes: 16 additions & 0 deletions gnovm/tests/files/type40.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

type (
Number = int32
Number2 = Number
)

func f(n Number) { println(n) }

func main() {
var n Number = 5
f(n)
}

// Output:
// 5

0 comments on commit 3524b0e

Please sign in to comment.