-
Notifications
You must be signed in to change notification settings - Fork 378
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
feat: add support for type declarations on pointer types #1733
feat: add support for type declarations on pointer types #1733
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1733 +/- ##
==========================================
+ Coverage 47.43% 47.79% +0.35%
==========================================
Files 384 393 +9
Lines 61205 61891 +686
==========================================
+ Hits 29032 29579 +547
- Misses 29744 29829 +85
- Partials 2429 2483 +54 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @ltzmaxwell. We just need to make sure that support for this feature is added in all places. I imagine there could be quite a few places that are currently casting to *PointerType
without bothering to ensure it is using the pointer's base type now that the pointer type can be a declared type.
Take this code as an example:
package main
type BytePtr *byte
func main() {
bs := []byte("hello")
var p BytePtr = &bs[0]
println(*p)
}
Running this will cause a panic. There is a line here that is incorrect: https://github.com/gnolang/gno/blob/master/gnovm/pkg/gnolang/op_expressions.go#L150
It should probably be changed to:
tv := TypedValue{T: bt.Elt}
to ensure it is using the base pointer type.
I haven't searched extensively but there may be other situations like this. This was one of the first hits that came up when I searched for .(*PointerType)
.
@ltzmaxwell |
yes I'm on it, sorry for the delay. |
this is added, also some other tests, thank you @deelawn ! |
Thanks for fixing the type assertion issues @ltzmaxwell. I can see one more thing that should be done to make this solution complete. Now that we support aliasing pointer types, we should also make the change to ensure that method receivers cannot have an underlying pointer type, as per the go spec https://arc.net/l/quote/mihfuukq, and also to avoid ambiguity for cases where this would currently be allowed. For example, this should fail during realm creation in the preprocessor with a message like package main
type IntPtr *int
var ip IntPtr = new(int)
func (p IntPtr) Int() int {
return *p
}
func main() {
println(ip.Int())
} This could also be a separate PR. What do you think @petar-dambovaliev |
Nice! as always. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job 👍
support type decl upon pointer type: