Skip to content

Commit

Permalink
fix(gnovm): handle type alias declaration for PrimitiveType (#3222)
Browse files Browse the repository at this point in the history
Fixes: #3203

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>
  • Loading branch information
hthieu1110 authored Dec 3, 2024
1 parent 8fa4997 commit a6f1aba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
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:
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

0 comments on commit a6f1aba

Please sign in to comment.