Skip to content

Commit c5e0749

Browse files
KevinRansomcartermp
authored andcommitted
Phillips original PR --- Add type name to error, if it's known, to undefined name error (#8346)
* Add type name to error, if it's known, to undefined name error * generic args too * Update tests round 1 * update the tests that aren't those dang baselines that I hate * some fsharpqa updates I guess * More test updates * updates lol * more updates * more fsharpqa updates * More fsharpqa updates * hope this 'n works * jojo * fsharpqa tests * fsharpqa tests * Update FixedIndexSliceTests.fs Co-authored-by: Phillip Carter <pcarter@fastmail.com>
1 parent 353ee6d commit c5e0749

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/fsharp/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
undefinedNameNamespace,"The namespace '%s' is not defined."
55
undefinedNameNamespaceOrModule,"The namespace or module '%s' is not defined."
66
undefinedNameFieldConstructorOrMember,"The field, constructor or member '%s' is not defined."
7+
undefinedNameFieldConstructorOrMemberWhenTypeIsKnown,"The type '%s' does not define the field, constructor or member '%s'."
78
undefinedNameValueConstructorNamespaceOrType,"The value, constructor, namespace or type '%s' is not defined."
89
undefinedNameValueOfConstructor,"The value or constructor '%s' is not defined."
910
undefinedNameValueNamespaceTypeOrModule,"The value, namespace, type or module '%s' is not defined."

src/fsharp/NameResolution.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,14 @@ let rec ResolveLongIdentInTypePrim (ncenv: NameResolver) nenv lookupKind (resInf
23592359
| _ -> ()
23602360
| _ -> ()
23612361

2362-
raze (UndefinedName (depth, FSComp.SR.undefinedNameFieldConstructorOrMember, id, suggestMembers))
2362+
let errorTextF s =
2363+
if isAppTy g ty then
2364+
let tcref = tcrefOfAppTy g ty
2365+
FSComp.SR.undefinedNameFieldConstructorOrMemberWhenTypeIsKnown(tcref.DisplayNameWithStaticParametersAndTypars, s)
2366+
else
2367+
FSComp.SR.undefinedNameFieldConstructorOrMember(s)
2368+
2369+
raze (UndefinedName (depth, errorTextF, id, suggestMembers))
23632370

23642371
and ResolveLongIdentInNestedTypes (ncenv: NameResolver) nenv lookupKind resInfo depth id m ad (id2: Ident) (rest: Ident list) findFlag typeNameResInfo tys =
23652372
tys

src/fsharp/tast.fs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,16 @@ and /// Represents a type definition, exception definition, module definition or
702702
| _ -> x.entity_opt_data <- Some { Entity.NewEmptyEntityOptData() with entity_compiled_name = name }
703703

704704
/// The display name of the namespace, module or type, e.g. List instead of List`1, and no static parameters
705-
member x.DisplayName = x.GetDisplayName(false, false)
705+
member x.DisplayName = x.GetDisplayName()
706+
707+
/// The display name of the namespace, module or type with <'T, 'U, 'V> added for generic types, plus static parameters if any
708+
member x.DisplayNameWithStaticParametersAndTypars = x.GetDisplayName(withStaticParameters=true, withTypars=true, withUnderscoreTypars=false)
706709

707710
/// The display name of the namespace, module or type with <_, _, _> added for generic types, plus static parameters if any
708-
member x.DisplayNameWithStaticParametersAndUnderscoreTypars = x.GetDisplayName(true, true)
711+
member x.DisplayNameWithStaticParametersAndUnderscoreTypars = x.GetDisplayName(withStaticParameters=true, withTypars=false, withUnderscoreTypars=true)
709712

710713
/// The display name of the namespace, module or type, e.g. List instead of List`1, including static parameters if any
711-
member x.DisplayNameWithStaticParameters = x.GetDisplayName(true, false)
714+
member x.DisplayNameWithStaticParameters = x.GetDisplayName(withStaticParameters=true, withTypars=false, withUnderscoreTypars=false)
712715

713716
#if !NO_EXTENSIONTYPING
714717
member x.IsStaticInstantiationTycon =
@@ -717,15 +720,20 @@ and /// Represents a type definition, exception definition, module definition or
717720
args.Length > 0
718721
#endif
719722

720-
member x.GetDisplayName(withStaticParameters, withUnderscoreTypars) =
723+
member x.GetDisplayName(?withStaticParameters, ?withTypars, ?withUnderscoreTypars) =
724+
let withStaticParameters = defaultArg withStaticParameters false
725+
let withTypars = defaultArg withTypars false
726+
let withUnderscoreTypars = defaultArg withUnderscoreTypars false
721727
let nm = x.LogicalName
728+
722729
let getName () =
723730
match x.TyparsNoRange with
724731
| [] -> nm
725732
| tps ->
726733
let nm = DemangleGenericTypeName nm
727-
if withUnderscoreTypars && not (List.isEmpty tps) then
728-
nm + "<" + String.concat "," (Array.create tps.Length "_") + ">"
734+
if (withUnderscoreTypars || withTypars) && not (List.isEmpty tps) then
735+
let typearNames = tps |> List.map (fun typar -> if withUnderscoreTypars then "_" else typar.Name)
736+
nm + "<" + String.concat "," typearNames + ">"
729737
else
730738
nm
731739

@@ -854,7 +862,7 @@ and /// Represents a type definition, exception definition, module definition or
854862
member x.Typars m = x.entity_typars.Force m
855863

856864
/// Get the type parameters for an entity that is a type declaration, otherwise return the empty list.
857-
member x.TyparsNoRange = x.Typars x.Range
865+
member x.TyparsNoRange: Typars = x.Typars x.Range
858866

859867
/// Get the type abbreviated by this type definition, if it is an F# type abbreviation definition
860868
member x.TypeAbbrev =
@@ -3362,6 +3370,9 @@ and
33623370
/// The display name of the namespace, module or type, e.g. List instead of List`1, not including static parameters
33633371
member x.DisplayName = x.Deref.DisplayName
33643372

3373+
/// The display name of the namespace, module or type with <'T, 'U, 'V> added for generic types, including static parameters
3374+
member x.DisplayNameWithStaticParametersAndTypars = x.Deref.DisplayNameWithStaticParametersAndTypars
3375+
33653376
/// The display name of the namespace, module or type with <_, _, _> added for generic types, including static parameters
33663377
member x.DisplayNameWithStaticParametersAndUnderscoreTypars = x.Deref.DisplayNameWithStaticParametersAndUnderscoreTypars
33673378

0 commit comments

Comments
 (0)