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

Parens: miscellaneous fixes #16262

Merged
merged 3 commits into from
Nov 14, 2023
Merged

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Nov 12, 2023

Another followup to #16079.

@brianrourkeboll brianrourkeboll requested a review from a team as a code owner November 12, 2023 20:49
Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

Thanks! Tests are getting to about 2000 LOC, if you come up with any fresh thoughts on splitting them - go ahead :)

@brianrourkeboll
Copy link
Contributor Author

Thanks! Tests are getting to about 2000 LOC, if you come up with any fresh thoughts on splitting them - go ahead :)

Fair enough :)

I'll see if I can find time this week to open a test cleanup PR.

@brianrourkeboll
Copy link
Contributor Author

brianrourkeboll commented Nov 13, 2023

Also, with the changes in #16248 and those in this PR applied, I can run the bulk fix on FSharp.Core and compile it with no errors or warnings—with the sole exception of this pair of parentheses in local.fs:

[|SR.GetString SR.notEnoughElements; index; (if index=1 then "element" else "elements")|]

Removing those parentheses results in:

FSC : error FS0193: The module/namespace 'Microsoft.FSharp.Collections' from compilation unit 'FSharp.Core' did not contain the namespace, module or type 'SeqModule'

(No line number is given, and there is no warning or error in VS.)

The reason seems to have something to do with the fact that the array comprehension's target type is obj array, which requires that both branches of the if-then-else expression be implicitly upcast to obj. The following lets FSharp.Core compile successfully, for example:

[|SR.GetString SR.notEnoughElements; index; box <| if index=1 then "element" else "elements" |]

It only seems to affect FSharp.Core, though—the following (AST) compiles and runs as you would expect in any other context:

let f x : obj array = [| "a"; 3; (if x = 1 then "element" else "elements") |]
printfn $"f 1 = %A{f 1}"
printfn $"f 2 = %A{f 2}"

let g x : obj array = [| "a"; 3; if x = 1 then "element" else "elements" |]
printfn $"g 1 = %A{g 1}"
printfn $"g 2 = %A{g 2}"

Is there some special way that FSharp.Core is compiled that would affect the way that expression is compiled?

Edit: there is. The error happens sometime during the CoreCompile task, specifically after the Import non-system references phase finishes and before the Typecheck phase timing is reported (although something happening between then and Typechecked would make more sense to me).

Otherwise, I guess I can just never suggest removing parens from around potentially problematic expressions in sequential expressions, although it should be valid in general when the parenthesized expression is the last expression in the sequence (compare the logic in ocamlformat).

@psfinaki
Copy link
Member

I'll see if I can find time this week to open a test cleanup PR.

Sure, this can be a followup.

Also, with the changes in #16248 and those in this PR applied, I can run the bulk fix on FSharp.Core and compile it with no errors or warnings

This is awesome!

with the sole exception of this pair of parentheses in local.fs

I guess it is worth creating a separate issue for this. Nothing comes to my mind on that, but this does not sound right or as anything I would want to happen in the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants