Skip to content

Disallow discarded EqualExpression for a struct with opEquals #22423

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.

Activity

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

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