Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 21, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Mismatch of array length |Mismatch of known array |during assignment should |length during dynamic => |emit better diagnostics |static array assignment | |should emit better | |diagnostics -- |
April 21, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|nobody@puremagic.com |andrej.mitrovich@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- Simplified test-case: ----- uint[2] arr1 = [1, 2, 3][0 .. 2]; uint[2] arr2 = [1, 2, 3][0 .. 3]; void main() { } ----- -- |
April 21, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|andrej.mitrovich@gmail.com |nobody@puremagic.com -- |
April 21, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |k.hara.pg@gmail.com --- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- Kenji: The way I see it, we need some way of returning back information on why some implicit conversion didn't work. For example, in 'implicitConvTo' in the visitor functions 'result' is simply initialized to MATCHnomatch if the dimensions of the two slices don't match. But this isn't propagate back to the caller side. We could vastly improve diagnostics for type mismatches, length mismatches, template instance failures, if we had a way of return back information. I think one way we could do it is to turn the MATCH enum into a struct, which internally holds more state. For example: struct MATCH { /// equivalent to what MATCH was before: MATCHnomatch, MATCHconvert... MATCHLevel level; /// call this to emit informative diagnostic const char*(*error_fp)(); } In internal matching routines the code could do (sorry this is a bit mixed-C/D code syntax): ----- if (e->elements->dim != tsa->dim->toInteger()) { result = MATCH(MATCHnomatch, { return format("Array length mismatch: %s %s", e->elements->dim, tsa->dim->toInteger()); } } ----- So the idea is the routine initializes a pointer, and then the call site can decide whether to call it to extract a diagnostic, or whether to ignore it. For example the 'resolveFuncCall' function typically walks through several template instances before it decides on emitting diagnostics, so having a lazy way of extracting a diagnostic is cruical. On the call site (e.g. 'resolveFuncCall') the code could look like: ----- if (matchresult.level == MATCHnomatch) { error("Failed to match: %s", matchresult.error_fp()); } ----- What do you think about this design? I'm not sure whether we can create delegates in C++ like we can in D though, I'm not too familiar with what's supported there. -- |
April 21, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 --- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- (In reply to Andrej Mitrovic from comment #2) > But this isn't propagate back to the caller side. propagated* -- |
April 21, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 --- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> --- (In reply to Andrej Mitrovic from comment #2) > So the idea is the routine initializes a pointer *A function pointer (well, a delegate in this case) -- |
April 22, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> --- https://github.com/D-Programming-Language/dmd/pull/3485 -- |
April 22, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 --- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> --- (In reply to Andrej Mitrovic from comment #2) > For example, in 'implicitConvTo' in the visitor functions 'result' is simply initialized to MATCHnomatch if the dimensions of the two slices don't match. But this isn't propagate back to the caller side. If e->implicitConvTo(t) returns MATCHnomatch, e->implicitCastTo(sc, t) should cause error which represents why e does not match to t. So, the following compiler code form would be sufficient. e = e->implicitCastTo(sc, t); or: if (e->implicitConvTo(t)) { e = e->implicitCastTo(sc, t); assert(e->op != TOKerror); // always succeeds } else { // extra handling for the unmatch, if e and t have known forms. if (...) { error("more better diagnostic for particular case"); e = new ErrorExp(); } // error report for generic case // (if e is already an ErrorExp, no redundant error generated) e = e->implicitCastTo(sc, t); } -- |
April 25, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 github-bugzilla@puremagic.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED -- |
April 25, 2014 [Issue 12606] Mismatch of known array length during dynamic => static array assignment should emit better diagnostics | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12606 --- Comment #7 from github-bugzilla@puremagic.com --- Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3b74627a464197f526e6b3a9a54334e3ced60fc8 fix Issue 12606 - Mismatch of known array length during dynamic => static array assignment should emit better diagnostics Recognize slice expression on initializer and rhs of assignment https://github.com/D-Programming-Language/dmd/commit/3a50fa40059ae790f783a691b13d4217cf4ac861 Merge pull request #3485 from 9rnsr/fix12606 Issue 12606 - Mismatch of known array length during dynamic => static array assignment should emit better diagnostics -- |
Copyright © 1999-2021 by the D Language Foundation