Skip to content

Disallow discarded EqualExpression for a struct with opEquals #22423

@ntrel

Description

@ntrel

The following errors:

	int x;
	x == 1;

structopeq.d(15): Error: the result of the equality expression x == 1 is discarded

It also errors for x++ == 1;, even though that has a side-effect.

This could be extended for EqualExpression when lowering to opEquals:

struct S
{
	bool opEquals(int);
}

void main()
{
	S s;
	s == 1; // currently allowed, should error
}

Similar to the PR to disallow discarded assignment, this should still error even if opEquals may have a side-effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions