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

Diagnostics/extended data: support NoConstructorsAvailableForType #16543

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Parser recovers on complex primary constructor patterns, better tree representation for primary constructor patterns. ([PR #16425](https://github.com/dotnet/fsharp/pull/16425))
* Name resolution: keep type vars in subsequent checks ([PR #16456](https://github.com/dotnet/fsharp/pull/16456))
* Diagnostics: extended data for NoConstructorsAvailableForType ([PR #16543](https://github.com/dotnet/fsharp/pull/16543))

### Changed

Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,8 @@ let ResolveLongIdentAsModuleOrNamespaceThen sink atMostOne amap m fullyQualified
// Bind name used in "new Foo.Bar(...)" constructs
//-------------------------------------------------------------------------

exception NoConstructorsAvailableForType of TType * DisplayEnv * range

let private ResolveObjectConstructorPrim (ncenv: NameResolver) edenv resInfo m ad ty =
let g = ncenv.g
let amap = ncenv.amap
Expand All @@ -2570,7 +2572,7 @@ let private ResolveObjectConstructorPrim (ncenv: NameResolver) edenv resInfo m a
[DefaultStructCtor(g, ty)]
else []
if (isNil defaultStructCtorInfo && isNil ctorInfos) || (not (isAppTy g ty) && not (isAnyTupleTy g ty)) then
raze (Error(FSComp.SR.nrNoConstructorsAvailableForType(NicePrint.minimalStringOfType edenv ty), m))
raze (NoConstructorsAvailableForType(ty, edenv, m))
else
let ctorInfos = ctorInfos |> List.filter (IsMethInfoAccessible amap m ad)
let metadataTy = convertToTypeWithMetadataIfPossible g ty
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Checking/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ exception internal IndeterminateType of range
/// Used to report a warning condition for the use of upper-case identifiers in patterns
exception internal UpperCaseIdentifierInPattern of range

exception internal NoConstructorsAvailableForType of TType * DisplayEnv * range

/// Generate a new reference to a record field with a fresh type instantiation
val FreshenRecdFieldRef: NameResolver -> range -> RecdFieldRef -> RecdFieldInfo

Expand Down
9 changes: 7 additions & 2 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ type Exception with
// DO NOT CHANGE THESE NUMBERS
| ErrorFromAddingTypeEquation _ -> 1
| FunctionExpected _ -> 2
| NotAFunctionButIndexer _ -> 3217
| NotAFunction _ -> 3
| FieldNotMutable _ -> 5
| Recursion _ -> 6
Expand Down Expand Up @@ -320,14 +319,16 @@ type Exception with
| BadEventTransformation _ -> 91
| HashLoadedScriptConsideredSource _ -> 92
| UnresolvedConversionOperator _ -> 93
| ArgumentsInSigAndImplMismatch _ -> 3218
// avoid 94-100 for safety
| ObsoleteError _ -> 101
#if !NO_TYPEPROVIDERS
| TypeProviders.ProvidedTypeResolutionNoRange _
| TypeProviders.ProvidedTypeResolution _ -> 103
#endif
| PatternMatchCompilation.EnumMatchIncomplete _ -> 104
| NoConstructorsAvailableForType _ -> 1133
| NotAFunctionButIndexer _ -> 3217
| ArgumentsInSigAndImplMismatch _ -> 3218

// Strip TargetInvocationException wrappers
| :? TargetInvocationException as e -> e.InnerException.DiagnosticNumber
Expand Down Expand Up @@ -605,6 +606,7 @@ module OldStyleMessages =
let MSBuildReferenceResolutionErrorE () = Message("MSBuildReferenceResolutionError", "%s%s")
let TargetInvocationExceptionWrapperE () = Message("TargetInvocationExceptionWrapper", "%s")
let ArgumentsInSigAndImplMismatchE () = Message("ArgumentsInSigAndImplMismatch", "%s%s")
let NoConstructorsAvailableForTypeE () = Message("NoConstructorsAvailableForType", "%s")

#if DEBUG
let mutable showParserStackOnParseError = false
Expand Down Expand Up @@ -1857,6 +1859,9 @@ type Exception with
| ArgumentsInSigAndImplMismatch(sigArg, implArg) ->
os.AppendString(ArgumentsInSigAndImplMismatchE().Format sigArg.idText implArg.idText)

| NoConstructorsAvailableForType(ty, denv, _) ->
os.AppendString(NoConstructorsAvailableForTypeE().Format(NicePrint.stringOfTy denv ty))

// Strip TargetInvocationException wrappers
| :? TargetInvocationException as exn -> exn.InnerException.Output(os, suggestNames)

Expand Down
1 change: 0 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,6 @@ lexfltSeparatorTokensOfPatternMatchMisaligned,"The '|' tokens separating rules o
1129,nrRecordDoesNotContainSuchLabel,"The record type '%s' does not contain a label '%s'."
1130,nrInvalidFieldLabel,"Invalid field label"
1132,nrInvalidExpression,"Invalid expression '%s'"
1133,nrNoConstructorsAvailableForType,"No constructors are available for the type '%s'"
1134,nrUnionTypeNeedsQualifiedAccess,"The union type for union case '%s' was defined with the RequireQualifiedAccessAttribute. Include the name of the union type ('%s') in the name you are using."
1135,nrRecordTypeNeedsQualifiedAccess,"The record type for the record field '%s' was defined with the RequireQualifiedAccessAttribute. Include the name of the record type ('%s') in the name you are using."
1136,ilwriteErrorCreatingPdb,"Unexpected error creating debug information file '%s'"
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/FSStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,9 @@
<data name="ArgumentsInSigAndImplMismatch" xml:space="preserve">
<value>The argument names in the signature '{0}' and implementation '{1}' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling.</value>
</data>
<data name="NoConstructorsAvailableForType" xml:space="preserve">
<value>No constructors are available for the type '{0}'</value>
</data>
<data name="Parser.TOKEN.WHILE.BANG" xml:space="preserve">
<value>keyword 'while!'</value>
</data>
Expand Down
30 changes: 20 additions & 10 deletions src/Compiler/Symbols/FSharpDiagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ module ExtendedData =
type IFSharpDiagnosticExtendedData = interface end

[<Experimental("This FCS API is experimental and subject to change.")>]
type TypeMismatchDiagnosticExtendedData
internal (symbolEnv: SymbolEnv, dispEnv: DisplayEnv, expectedType: TType, actualType: TType, context: DiagnosticContextInfo) =
type TypeMismatchDiagnosticExtendedData(symbolEnv: SymbolEnv, dispEnv: DisplayEnv, expectedType: TType, actualType: TType, context: DiagnosticContextInfo) =

interface IFSharpDiagnosticExtendedData

member x.ExpectedType = FSharpType(symbolEnv, expectedType)
Expand All @@ -78,35 +78,45 @@ module ExtendedData =
member x.DisplayContext = FSharpDisplayContext(fun _ -> dispEnv)

[<Experimental("This FCS API is experimental and subject to change.")>]
type ExpressionIsAFunctionExtendedData
internal (symbolEnv: SymbolEnv, actualType: TType) =
type ExpressionIsAFunctionExtendedData(symbolEnv: SymbolEnv, actualType: TType) =

interface IFSharpDiagnosticExtendedData

member x.ActualType = FSharpType(symbolEnv, actualType)

[<Experimental("This FCS API is experimental and subject to change.")>]
type FieldNotContainedDiagnosticExtendedData
internal (symbolEnv: SymbolEnv, implTycon: Tycon, sigTycon: Tycon, signatureField: RecdField, implementationField: RecdField) =
type FieldNotContainedDiagnosticExtendedData(symbolEnv: SymbolEnv, implTycon: Tycon, sigTycon: Tycon, signatureField: RecdField, implementationField: RecdField) =

interface IFSharpDiagnosticExtendedData

member x.SignatureField = FSharpField(symbolEnv, RecdFieldRef.RecdFieldRef(mkLocalTyconRef sigTycon, signatureField.Id.idText))
member x.ImplementationField = FSharpField(symbolEnv, RecdFieldRef.RecdFieldRef(mkLocalTyconRef implTycon, implementationField.Id.idText))

[<Experimental("This FCS API is experimental and subject to change.")>]
type ValueNotContainedDiagnosticExtendedData
internal (symbolEnv: SymbolEnv, signatureValue: Val, implValue: Val) =
type ValueNotContainedDiagnosticExtendedData(symbolEnv: SymbolEnv, signatureValue: Val, implValue: Val) =

interface IFSharpDiagnosticExtendedData

member x.SignatureValue = FSharpMemberOrFunctionOrValue(symbolEnv, mkLocalValRef signatureValue)
member x.ImplementationValue = FSharpMemberOrFunctionOrValue(symbolEnv, mkLocalValRef implValue)

[<Experimental("This FCS API is experimental and subject to change.")>]
type ArgumentsInSigAndImplMismatchExtendedData
internal(sigArg: Ident, implArg: Ident) =
type ArgumentsInSigAndImplMismatchExtendedData(sigArg: Ident, implArg: Ident) =

interface IFSharpDiagnosticExtendedData

member x.SignatureName = sigArg.idText
member x.ImplementationName = implArg.idText
member x.SignatureRange = sigArg.idRange
member x.ImplementationRange = implArg.idRange

[<Experimental("This FCS API is experimental and subject to change.")>]
type TypeUsageErrorExtendedData(ty: TType, symbolEnv: SymbolEnv) =

interface IFSharpDiagnosticExtendedData

member x.Type = FSharpType(symbolEnv, ty)

open ExtendedData

type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: string, subcategory: string, errorNum: int, numberPrefix: string, extendedData: IFSharpDiagnosticExtendedData option) =
Expand Down
21 changes: 16 additions & 5 deletions src/Compiler/Symbols/FSharpDiagnostic.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ module public ExtendedData =

/// Contextually-relevant data to each particular diagnostic
[<Interface; Experimental("This FCS API is experimental and subject to change.")>]
type public IFSharpDiagnosticExtendedData =
type IFSharpDiagnosticExtendedData =
interface
end

/// Additional data for type-mismatch-like (usually with ErrorNumber = 1) diagnostics
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type public TypeMismatchDiagnosticExtendedData =
type TypeMismatchDiagnosticExtendedData =
interface IFSharpDiagnosticExtendedData

/// Represents F# type expected in the current context
member ExpectedType: FSharpType
/// Represents F# type type actual in the current context
Expand All @@ -65,24 +66,27 @@ module public ExtendedData =

/// Additional data for 'This expression is a function value, i.e. is missing arguments' diagnostic
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type public ExpressionIsAFunctionExtendedData =
type ExpressionIsAFunctionExtendedData =
interface IFSharpDiagnosticExtendedData

/// Represents F# type of the expression
member ActualType: FSharpType

/// Additional data for diagnostics about a field whose declarations differ in signature and implementation
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type public FieldNotContainedDiagnosticExtendedData =
type FieldNotContainedDiagnosticExtendedData =
interface IFSharpDiagnosticExtendedData

/// Represents F# field in signature file
member SignatureField: FSharpField
/// Represents F# field in implementation file
member ImplementationField: FSharpField

/// Additional data for diagnostics about a value whose declarations differ in signature and implementation
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type public ValueNotContainedDiagnosticExtendedData =
type ValueNotContainedDiagnosticExtendedData =
interface IFSharpDiagnosticExtendedData

/// Represents F# value in signature file
member SignatureValue: FSharpMemberOrFunctionOrValue
/// Represents F# value in implementation file
Expand All @@ -92,6 +96,7 @@ module public ExtendedData =
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type ArgumentsInSigAndImplMismatchExtendedData =
interface IFSharpDiagnosticExtendedData

/// Argument name in signature file
member SignatureName: string
/// Argument name in implementation file
Expand All @@ -101,6 +106,12 @@ module public ExtendedData =
/// Argument identifier range within implementation file
member ImplementationRange: range

[<Class; Experimental("This FCS API is experimental and subject to change.")>]
type TypeUsageErrorExtendedData =
interface IFSharpDiagnosticExtendedData

member Type: FSharpType

open ExtendedData

/// Represents a diagnostic produced by the F# compiler
Expand Down
5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading