Skip to content

add note about VRP not applying to assignment operator exps#23101

Open
WalterBright wants to merge 1 commit into
dlang:masterfrom
WalterBright:AssOpExp
Open

add note about VRP not applying to assignment operator exps#23101
WalterBright wants to merge 1 commit into
dlang:masterfrom
WalterBright:AssOpExp

Conversation

@WalterBright
Copy link
Copy Markdown
Member

For reference: #19075 (comment)

@WalterBright WalterBright added the Spec Issues and PR about the language specification label May 8, 2026
@WalterBright
Copy link
Copy Markdown
Member Author

/tmpfs/dautotest-work/repo/dlang.org/web/spec/expression.html:145: [RAW MACRO LEAKAGE] $(SPEC_S Expressions,

What does that mean?

@Herringway
Copy link
Copy Markdown
Contributor

I'm not sure, but it looks like your parentheses are unbalanced here.

@dkorpel
Copy link
Copy Markdown
Contributor

dkorpel commented May 8, 2026

It's opening a double link

$(LINK2 $(DDSUBLINK

@WalterBright
Copy link
Copy Markdown
Member Author

@dkorpel thanks!

Comment thread spec/expression.dd
the binary operators. Still the left operand must be an lvalue.
)

$(P $(DDSUBLINK spec/type.html, vrp, Value Range Propagation) does not apply to assignment operator expressions:)
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.

VRP is part of implicit conversions. For built-in types, a op= b is defined as doing a cast / explicit conversion, so VRP isn't even a possibility. And for custom types, where an implicit conversion happens to the argument type, VRP does apply:

struct S
{
	auto opOpAssign(string op)(ubyte value)
	{
		return this;
	}
}

void f(S b, uint i)
{
	b *= i;        // Error
	b *= i & 0xFF; // No error
}

So the statement is either irrelevant or incorrect, it's best left out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The spec for a op= b can certainly be adapted to do VRP. As for opOpAssign, it is up to the user implementation of it to use VRP or not.

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.

it is up to the user implementation of it to use VRP or not.

Then the PR should demonstrate that instead of stating something false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Spec Issues and PR about the language specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants