-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
incorrect ProveInit
with delayed initialization of field
#3608
Comments
Not enough context. It could be that 'result' has not-nil fields etc. |
ok, here is the minimal code to reproduce the warning type
xx = ref object of RootObj
a: range[0..0x7FFFFFFF]
zz = ref object of xx
b: range[1..0x7FFFFFFF]
proc make[T](): T = new(result)
discard make[xx]()
discard make[zz]() #if this line is removed, the warning dissapear shouldn't both line cause warning? and why uninitialized range should become compile time error in the future? couldn't the uninitialized range like range[1..n] just given value 1 like range[0..n] default value is 0? |
this very simple example also produce incorrrect warning same as above type
abc* = ref object
w: range[2..100]
proc createABC(): abc =
new(result)
result.w = 20 #i think the compiler missed to check this part the warning doesn't make any sense, right? |
On the contrary, it works as designed. That doesn't mean I like it, but it is not a bug. Use this instead: proc createABC(): abc =
result = abc(w: 20) |
then it is an unpleasant feature, reduce code/coding flexibility |
IME it works well enough. |
@Araq Your suggestion works in this simple case, but not in more complex ones. For instance type
Foo* = ref object
w: range[2..100]
Bar* = ref object
w: range[10..50]
template create(result: expr) =
new(result)
result.w = 20
proc createFoo(): Foo = create(result)
proc createBar(): Bar = create(result) In the template here you do not know if you are creating a This is not a theoretical possibility: it is happening always to me when dealing with similar 32-bit/64-bit code. |
Couldn't you do something like (untested): result = new type(result) |
In my case type
Matrix32*[M, N: static[int]] = object
order: OrderType
data: ref array[N * M, float32]
Matrix64*[M, N: static[int]] = object
order: OrderType
data: ref array[M * N, float64] Changing template makeSMatrixPrivate(M, N, f, order, result: expr) =
new result.data
result.order = order
# ... into template makeSMatrixPrivate(M, N, f, order, result: expr) =
result.data = new type(result.data)
result.order = order
# ... did not make the warning go away. |
But that might work: template makeSMatrixPrivate(M, N, f, orderParam, result: expr) =
result.data = type(result.data)(order: orderParam)
# ... |
Unfortunately, it doesn't seem to work. I have switched to this style in a proveinit branch of linalg, but the warnings are still there (just try |
This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions. |
ProveInit
with delayed initialization of field
* fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for #16744 * add testcase for #3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <[email protected]>
* fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for nim-lang#16744 * add testcase for nim-lang#3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <[email protected]>
* fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for #16744 * add testcase for #3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <[email protected]> (cherry picked from commit f89ba2c)
produces warning:
how could the 'result' is not initialized? 😄
The text was updated successfully, but these errors were encountered: