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

FSI type mismatch when order of generic parameters don't match #15175

Closed
Eliemer opened this issue May 2, 2023 · 1 comment · Fixed by #15366
Closed

FSI type mismatch when order of generic parameters don't match #15175

Eliemer opened this issue May 2, 2023 · 1 comment · Fixed by #15366
Labels
Area-Compiler-SigFileGen generation of signature files - both compiler and IDE Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@Eliemer
Copy link

Eliemer commented May 2, 2023

If i use explicit generic type arguments in my implementation file, BUT they dont match the order in which they are used in the function, the compiler throws a type mismatch error between the (auto-generated) fsi files and the fs file.

Specifically, if my implementation function declares 'a then 'b but goes on to use 'b first in its implementation signature, the FSI file wont capture that detail and completely misunderstand the order of generics used.

fsi file

val f: x: 'b -> y: 'a -> unit

implementation file

let f<'a, 'b> 
    (x: 'b)
    (y: 'a)
    = printfn "%A %A" x y 

Results in

... Program.fs(1,5): error FS0034: Module 'Program' contains↔     
val f: x: 'a -> y: 'b -> unit    ↔but its signature specifies↔    val f: x: 'b -> y: 'a -> unit    ↔The types differ[...]

Repro steps

Provide the steps required to reproduce the problem:

  1. dotnet new classlib -lang F#
  2. <insert code above>
  3. dotnet build -p:OtherFlags="--allsigs" OR manually create above FSI file
  4. include .fsi in project file
  5. dotnet build

Expected behavior

No compiler error, previous dotnet build ensures theres no errors present in code

Actual behavior

type mismatch compiler error, signature file has the order of generic parameters in order of appearance, regardless of order of implementation

Known workarounds

Implementation MUST declare generic parameters in order of appearance

Related information

Provide any related information (optional):

.NET SDK: 7.0.203 (also tried with prerelease 7.0.400-preview.23226.4)
OS: Windows 11

@github-actions github-actions bot added this to the Backlog milestone May 2, 2023
@0101 0101 added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Compiler-SigFileGen generation of signature files - both compiler and IDE and removed Needs-Triage labels May 15, 2023
@nojaf
Copy link
Contributor

nojaf commented Jun 12, 2023

Another workaround appears to be to include the parameters in the right order in the signature file:
val f<'a,'b> : x: 'b -> y: 'a -> unit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-SigFileGen generation of signature files - both compiler and IDE Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants