Skip to content

Fix #22983 - Named argument allowed in int(x: 3)#22984

Merged
thewilsonator merged 2 commits into
dlang:masterfrom
dkorpel:named-arg-scalar-error
Apr 20, 2026
Merged

Fix #22983 - Named argument allowed in int(x: 3)#22984
thewilsonator merged 2 commits into
dlang:masterfrom
dkorpel:named-arg-scalar-error

Conversation

@dkorpel
Copy link
Copy Markdown
Contributor

@dkorpel dkorpel commented Apr 19, 2026

Closes #22983

Updates the parser for consistency and to match the grammar

@dlang-bot
Copy link
Copy Markdown
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22984"

Copy link
Copy Markdown
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks good

Comment thread compiler/src/dmd/expressionsem.d Outdated
{
if (exp.names && (*exp.names)[0].name)
{
error(exp.loc, "no named argument `%s` allowed for scalar", (*exp.names)[0].name.toErrMsg());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dkorpel dkorpel force-pushed the named-arg-scalar-error branch from 4ba6099 to 132cde7 Compare April 20, 2026 10:21
@thewilsonator thewilsonator merged commit 96e351f into dlang:master Apr 20, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Named argument allowed in int(x: 3)

3 participants