Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec/expression.dd
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,16 @@ $(H3 $(LNAME2 assignment_operator_expressions, Assignment Operator Expressions))
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.


---
void f(ubyte b, int i)
{
b = b * i; // Error: cannot implicitly convert expression `cast(int)b * i` of type `int` to `ubyte`
b *= i; // no error
}
---

$(H2 $(LNAME2 conditional_expressions, Conditional Expressions))

$(GRAMMAR
Expand Down
Loading