Skip to content

Conversation

@Delta456
Copy link
Member

No description provided.

receiver_sym := c.table.get_type_symbol(node.receiver.typ)
param_sym := c.table.get_type_symbol(node.params[1].typ)
if receiver_sym.name != param_sym.name ||
param_sym.kind !in [.struct_, .alias] || receiver_sym.kind !in [.struct_, .alias] {
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to add a check for .alias due to C interpolation in math.big module.

c.error('operator methods are only allowed for struct and type alias',
node.pos)
} else {
if param_sym.name != receiver_sym.name {
Copy link
Member

Choose a reason for hiding this comment

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

if node.receiver.typ != node.params[1].typ {

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! It is much better!

@Delta456 Delta456 closed this Dec 31, 2020
@Delta456 Delta456 reopened this Dec 31, 2020
@medvednikov medvednikov merged commit a834f33 into vlang:master Dec 31, 2020
@medvednikov
Copy link
Member

Good job @Delta456

@Delta456 Delta456 deleted the operator_overloading_check branch December 31, 2020 11:39
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.

4 participants