FS0193 on a call with an explicit type argument after an earlier call with the same argument types picked another overload (works in the .NET 10 SDK)

Aperta
#20,934 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
fsharp
Ambito
compilers

Direzione di ricerca

Start with the overload resolution behavior described in the repro and run dotnet fsi repro.fsx using the provided script. The issue also points to FSharp.Compiler.ComponentTests and a failing Assert.Equal call in TransparentCompiler.fs; inspect the related component tests to locate the regression. Done means both calls compile and select the overloads described, with the component test passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Needs-Triage Regression

In the .NET 11 SDK (11.0.100-rc.1 and 11.0.100-rc.3) a call with an explicit type argument is rejected when an earlier call, with the same argument types but a different type argument, resolved to another overload of the same method. The .NET 10 SDK compiles the same code.

Repro steps

Save as repro.fsx and run dotnet fsi repro.fsx:

type A =
    static member Eq<'T>(x: 'T, y: 'T) = "T,T"
    static member Eq<'T>(x: seq<'T>, y: seq<'T>) = "seq,seq"

let first = A.Eq<int>([ 1 ], [ 1 ])        // picks the seq overload
let second = A.Eq<int list>([ 1 ], [ 1 ])  // should pick the 'T,'T overload with 'T = int list

Expected behavior

Both calls compile, and second picks Eq<'T>(x: 'T, y: 'T) with 'T = int list, as it does when it is the only call. On the .NET 10.0.402 SDK (F# 10) the script compiles and prints seq,seq and T,T.

Actual behavior

repro.fsx(6,29): error FS0193: Type constraint mismatch. The type
    'int list'
is not compatible with type
    'int list seq'

Without the first call the second one compiles and picks the T,T overload. It looks as if the result of resolving an overloaded call is remembered under the method and the argument types only, without the explicit type arguments.

Known workarounds

Give the two calls different argument types (for example arrays for one of them), or use the same explicit type argument in both.

Related information

  • Reproduces with 11.0.100-rc.1.26420.103 and 11.0.100-rc.3.26522.148 (dotnet fsi), Windows 11. Does not reproduce with 10.0.402.
  • Found in this repository's FSharp.Compiler.ComponentTests: Assert.Equal<ReferenceOnDisk>(list, list) in one file (xUnit's Equal<T>(IEnumerable<T>, IEnumerable<T>)) made Assert.Equal<ProjectSnapshot.ReferenceOnDisk list>(list, list) in a later file (TransparentCompiler.fs) fail with the same error.
Lingua principale
F#
Stelle
4.3k
Fork
883
Merge medio
3g 4h
PR unite (30g)
88

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/fsharp

Tutte le issue di dotnet/fsharp

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.