Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected type conflation in binop handler #11392

Closed
Simn opened this issue Nov 19, 2023 · 2 comments
Closed

Expected type conflation in binop handler #11392

Simn opened this issue Nov 19, 2023 · 2 comments
Assignees

Comments

@Simn
Copy link
Member

Simn commented Nov 19, 2023

While looking at #11391 I noticed that there's some chaos in operators.ml with regards to with_type. In particular, type_binop2 currently receives only one expected type, but it should really be two: one for the typing of the rhs and one for the typing of the resulting binop.

Will try to construct a failing example.

@Simn Simn self-assigned this Nov 19, 2023
@Simn
Copy link
Member Author

Simn commented Nov 19, 2023

I don't think there's a failing example here because with_type isn't actually used beyond that point.

Another problem is that we type the lhs of assignments with the expected type of the whole binop. This isn't always correct which can easily be seen at block-level:

function main() {
	var a:Int;
	$type(a, _) = 0;
}

This prints Warning : Int (expected: NoValue), which is wrong because we clearly want a value to assign to.

@Simn
Copy link
Member Author

Simn commented Nov 19, 2023

I'm not even sure if it's technically correct to do this when there is an expected type:

function main() {
	var a:Int;
	var b:Int;
	$type(a, _) = $type(b, _) = 0;
}
source/Main.hx:4: characters 8-9 : Warning : Int (expected: NoValue)
source/Main.hx:4: characters 22-23 : Warning : Int (expected: WithType(Int, None))

While it's true that the result of b = 0 can be expected to be of type Int, that doesn't necessarily mean that b itself can be expected to be of type Int. This is more obvious when we look at it as a = (b = 0).

@Simn Simn closed this as completed in 52bb475 Nov 19, 2023
0b1kn00b pushed a commit to 0b1kn00b/haxe that referenced this issue Jan 25, 2024
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

No branches or pull requests

1 participant