D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23355 - invalid template parameter loses error location in some cases
Summary: invalid template parameter loses error location in some cases
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-09-21 19:53 UTC by Jan Jurzitza
Modified: 2022-09-22 07:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jan Jurzitza 2022-09-21 19:53:47 UTC
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 mhh 2022-09-21 20:49:58 UTC
This happens because the compiler parses T[n] as an associative array type and types don't have locations
Comment 2 Dlang Bot 2022-09-21 21:27:41 UTC
@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 Dlang Bot 2022-09-22 07:47:26 UTC
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 <maxhaton@gmail.com>

https://github.com/dlang/dmd/pull/14465