-
Notifications
You must be signed in to change notification settings - Fork 847
Closed
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.(Internal MS Team use only) Describes an issue with extreme impact on existing code.good first issuehelp wanted
Milestone
Description
When using nameof in a pattern match, I'd expect the compiler to infer the argument type as string since nameof returns a string. However, the argument is treated as generic and generates invalid IL.
Repro steps
// Expected:
// FS0001: This expression was expected to have type 'int' but here has type 'string'
// Actual:
// No compile error; InvalidProgramException at runtime.
match 3 with
| nameof int -> true
| _ -> false// Expected inferred type:
// val f : x:string -> bool
// Actual inferred type:
// val f : x:'a -> bool
let f x = match x with nameof x -> true | _ -> falseAccording to the RFC for the nameof pattern feature, the nameof expr should be "equivalent to a literal string pattern" which is not being respected.
Expected behavior
Expect the compiler to infer argument type as string when nameof is used in a pattern match.
Actual behavior
Compiler infers argument type as generic argument when nameof is used in a pattern match.
Known workarounds
Explicit type annotation.
let f (x:string) = match x with nameof x -> true | _ -> falsebrianrourkeboll and adelarsq
Metadata
Metadata
Assignees
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.(Internal MS Team use only) Describes an issue with extreme impact on existing code.good first issuehelp wanted
Type
Projects
Status
Done