Bug 23355 – invalid template parameter loses error location in some cases

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-09-21T19:53:47Z
Last change time
2022-09-22T07:47:26Z
Keywords
pull
Assigned to
No Owner
Creator
Jan Jurzitza

Comments

Comment #0 by d.bugs — 2022-09-21T19:53:47Z
Reproduction test case file: void ffi(T)(T[n] s) { } void main() { int[4] x; ffi(x); } When trying to compile this, the following messages are output: Error: undefined identifier `n` a.d(3): Error: none of the overloads of template `a.ffi` are callable using argument types `!()(int[4])` a.d(1): Candidate is: `ffi(T)(T[n] s)` note how the first error is missing context (would expect `a.d(1):` here) In this particular case it's not a hard issue, because the following errors show that there is an issue. However in my real project I have this function in another file in some weird configuration where there are no other errors other than the context-less error. So in my real project all I get is: Error: undefined identifier `n` Error: undefined identifier `n` Error: undefined identifier `n` Error: undefined identifier `n` which is harder to debug.
Comment #1 by maxhaton — 2022-09-21T20:49:58Z
This happens because the compiler parses T[n] as an associative array type and types don't have locations
Comment #2 by dlang-bot — 2022-09-21T21:27:41Z
@WebFreak001 updated dlang/dmd pull request #14465 "fix 23355: invalid template parameter loses error location in some cases (T[UndefinedIdentifier] has no error loc)" fixing this issue: - fix 23355: T[UndefinedIdentifier] has no error loc Types (e.g. TypeAArray) don't have a location attached to them, so instead of trying to use that we instead use the error location from the general template parameters. - add test for issue 23355 https://github.com/dlang/dmd/pull/14465
Comment #3 by dlang-bot — 2022-09-22T07:47:26Z
dlang/dmd pull request #14465 "fix 23355: invalid template parameter loses error location in some cases (T[UndefinedIdentifier] has no error loc)" was merged into master: - bbd03ee16ad8c46897ce74044148e02b562c0ee9 by WebFreak001: fix 23355: T[UndefinedIdentifier] has no error loc Types (e.g. TypeAArray) don't have a location attached to them, so instead of trying to use that we instead use the error location from the general template parameters. Co-authored-by: mhh <[email protected]> https://github.com/dlang/dmd/pull/14465