Fix #22983 - Named argument allowed in int(x: 3)#22984
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
thewilsonator
left a comment
There was a problem hiding this comment.
Otherwise looks good
| { | ||
| if (exp.names && (*exp.names)[0].name) | ||
| { | ||
| error(exp.loc, "no named argument `%s` allowed for scalar", (*exp.names)[0].name.toErrMsg()); |
There was a problem hiding this comment.
The term "scalar" usually refers to objects involved in equations, antonym of vector. Presumably this extends to all basic constructible types? If so please use "basic type".
For reference git grep scalar (restricted to the compiler directory returns
compiler/src/dmd/clone.d: if (!cldec || cldec.cppDtorVtblIndex == -1) // scalar deleting dtor not built for non-virtual dtors
compiler/src/dmd/dcast.d: // scalar op scalar - we shouldn't be here
compiler/src/dmd/expression.d: else if (_this.ty == Tenum || _this.ty == Tpointer) // the enum is possibly scalar
compiler/src/dmd/expressionsem.d: error(exp.loc, "no named argument `%s` allowed for scalar", (*exp.names)[0].name.toChars());
compiler/src/dmd/expressionsem.d: error(e.loc, "`%s` is not a scalar, it is a `%s`", e.toErrMsg(), e.type.toChars());
compiler/src/dmd/glue/e2ir.d: // For arrays of scalars (except floating types) of same size & signedness, void[],
compiler/src/dmd/iasm/dmdx86.d: // Scalar return values will always be in AX. So if it is a scalar
compiler/src/dmd/iasm/dmdx86.d: // then asm block sets return value if it modifies AX, if it is non-scalar
compiler/test/fail_compilation/named_arguments_error.d:fail_compilation/named_arguments_error.d(45): Error: no named argument `number` allowed for scalar
compiler/test/runnable/template2.d: // multiply by scalar (a * 2.0)
compiler/test/runnable/template2.d: // divide by scalar (a / b)
compiler/test/runnable/template2.d: // multiply by scalar (a * 2.0)
compiler/test/runnable/template2.d: // divide by scalar (a / b)
It would be good to adjust the other named argument errors too if they fall into the same case as this.
There was a problem hiding this comment.
The error is inside a branch if (exp.e1.op == EXP.type && t1.isScalar()) and the exact same as the existing error for new T(3) where T is a scalar type. That being side, other than __traits(isScalar), the term isn't very common from the user's side, so generalizing to 'basic type' is better.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4ba6099 to
132cde7
Compare
Closes #22983
Updates the parser for consistency and to match the grammar