Bug 21992 – importC: Error: variable is used as a type
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-04T21:38:40Z
Last change time
2021-07-04T23:27:58Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-06-04T21:38:40Z
The parser is unable to handle ambiguity well for cast expressions.
---
int test()
{
int i = 1;
int j = (i) * 2;
}
Comment #1 by bugzilla — 2021-06-27T10:18:46Z
Unfortunately, the (i)*2 can be parsed as either a multiply of i*2 or a cast of *2 to type i.
This can only be distinguished in the semantic phase when what i is is known.
Comment #2 by bugzilla — 2021-06-27T23:38:46Z
Because ( ) are not seen by the semantic code, the best solution is for the parser to turn (i)*2 into a cast expression. Then, if the semantic pass determines that i is a variable, rewrite the cast expression into a multiply.
Do the analogous thing for -, +, and & operators.
Comment #3 by ibuclaw — 2021-06-28T08:55:03Z
(In reply to Walter Bright from comment #2)
> Because ( ) are not seen by the semantic code, the best solution is for the
> parser to turn (i)*2 into a cast expression. Then, if the semantic pass
> determines that i is a variable, rewrite the cast expression into a multiply.
>
> Do the analogous thing for -, +, and & operators.
Yes, this is what I have in the pipeline already.
Comment #4 by ibuclaw — 2021-06-28T08:57:13Z
At the moment I do have some lvalue checking in the parser, this'll have to be moved to semantic as well. But there are some hurdles to overcome - mostly from the semantic lowering rvalues into lvalues.
For example, this nudges support in the right direction: https://github.com/dlang/dmd/pull/12752
Comment #5 by dlang-bot — 2021-07-04T18:21:06Z
@ibuclaw created dlang/dmd pull request #12808 "fix Issue 21992 - importC: Error: variable is used as a type" fixing this issue:
- fix Issue 21992 - importC: Error: variable is used as a type
https://github.com/dlang/dmd/pull/12808
Comment #6 by dlang-bot — 2021-07-04T23:27:58Z
dlang/dmd pull request #12808 "fix Issue 21992 - importC: Error: variable is used as a type" was merged into master:
- fb4583eb93aba712bcbcda5d7bdf6303d6c1416e by Iain Buclaw:
fix Issue 21992 - importC: Error: variable is used as a type
https://github.com/dlang/dmd/pull/12808