-
Notifications
You must be signed in to change notification settings - Fork 77
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
compiler: set default values for complex struct fields (2.x) #952
Conversation
Can't we use a |
Yes, this is one way to fix this, however each such fix requires proper type conversions in other array related opcodes (e.g. emitting proper |
If we're not supporting it then failing to compile is an option. I understand that it's easy to fix in Neo 3 because of native |
I noticed in package foo
type bar struct {
x int
}
func foo(i int) interface{} {
if i > 0 {
return bar{x: i}
}
return nil
}
func Main() int {
f := foo(1)
if f != nil {
return 1
}
return 2
} Maybe it is somehow related to solving issue. |
Codecov Report
@@ Coverage Diff @@
## master-2.x #952 +/- ##
==============================================
+ Coverage 67.74% 67.89% +0.14%
==============================================
Files 146 146
Lines 14384 14404 +20
==============================================
+ Hits 9744 9779 +35
+ Misses 4177 4162 -15
Partials 463 463
Continue to review full report at Codecov.
|
Set default value also for complex (struct, map) types. Note: because VM does not distinguish empty array and nil array, comparison 'a == nil' can't be handled properly without substantial effort. This will be fixed in NEO3.
NEO VM does not distinguish between empty and nil slices. Supporting this is not easy and requires changing lots of other opcodes. Pointers are not supported anyway and slices can be checked for emptiness by inspecting their `len`.
Dispatch based on types similarly to EQUAL.
Closes #949 .
There is no way we can distinguish
[]int(nil)
from[]int{}
without substantial effort. And even then array is a reference type so it's instance is equal only to itself in NeoVM.There is a simple workaround for checking if slice is empty:
len(arr) == 0
.nil
!=
processing.