From d8297b2dee5f4d41fdc1d7f9a7ca06a69ad8ee8e Mon Sep 17 00:00:00 2001 From: kerams Date: Sat, 17 Dec 2022 13:50:18 +0100 Subject: [PATCH 1/2] Allow type providers to report diagnostics for static parameters --- src/Compiler/Checking/CheckExpressions.fs | 28 +++-- src/Compiler/FSComp.txt | 1 + src/Compiler/TypedTree/TypeProviders.fs | 112 ++++++++++++++------ src/Compiler/TypedTree/TypeProviders.fsi | 13 ++- src/Compiler/xlf/FSComp.txt.cs.xlf | 5 + src/Compiler/xlf/FSComp.txt.de.xlf | 5 + src/Compiler/xlf/FSComp.txt.es.xlf | 5 + src/Compiler/xlf/FSComp.txt.fr.xlf | 5 + src/Compiler/xlf/FSComp.txt.it.xlf | 5 + src/Compiler/xlf/FSComp.txt.ja.xlf | 5 + src/Compiler/xlf/FSComp.txt.ko.xlf | 5 + src/Compiler/xlf/FSComp.txt.pl.xlf | 5 + src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 + src/Compiler/xlf/FSComp.txt.ru.xlf | 5 + src/Compiler/xlf/FSComp.txt.tr.xlf | 5 + src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 + src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 + src/FSharp.Core/fslib-extra-pervasives.fs | 16 +++ src/FSharp.Core/fslib-extra-pervasives.fsi | 15 +++ tests/service/data/TestTP/ProvidedTypes.fs | 56 ++++++++-- tests/service/data/TestTP/ProvidedTypes.fsi | 12 +++ tests/service/data/TestTP/TestTP.fs | 37 ++++++- 22 files changed, 304 insertions(+), 51 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index d4ff82dd1da..96fd6db9469 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4759,23 +4759,37 @@ and CrackStaticConstantArgs (cenv: cenv) env tpenv (staticParameters: Tainted + let startOffset, endOffset = + match kind with + | SynStringKind.Regular -> 1, 1 + | SynStringKind.Verbatim -> 2, 1 + | SynStringKind.TripleQuote -> 3, 3 + + mkFileIndexRange m.FileIndex (mkPos m.StartLine (m.StartColumn + startOffset)) (mkPos m.EndLine (m.EndColumn - endOffset)) + |> Some + | _ -> + None + staticParameters |> Array.mapi (fun i sp -> let spKind = Import.ImportProvidedType cenv.amap m (sp.PApply((fun x -> x.ParameterType), m)) let spName = sp.PUntaint((fun sp -> sp.Name), m) if i < unnamedArgs.Length then - let v = unnamedArgs[i] - let v, _tpenv = TcStaticConstantParameter cenv env tpenv spKind v None container - v + let arg = unnamedArgs[i] + let v, _tpenv = TcStaticConstantParameter cenv env tpenv spKind arg None container + { Name = spName; Value = v; ValueRange = arg.Range; ValueRangeAdjusted = adjustRangeForQuotes arg } else match namedArgs |> List.filter (fun (n, _) -> n.idText = spName) with - | [(n, v)] -> - let v, _tpenv = TcStaticConstantParameter cenv env tpenv spKind v (Some n) container - v + | [(n, arg)] -> + let v, _tpenv = TcStaticConstantParameter cenv env tpenv spKind arg (Some n) container + { Name = spName; Value = v; ValueRange = arg.Range; ValueRangeAdjusted = adjustRangeForQuotes arg } | [] -> if sp.PUntaint((fun sp -> sp.IsOptional), m) then match sp.PUntaint((fun sp -> sp.RawDefaultValue), m) with | Null -> error (Error(FSComp.SR.etStaticParameterRequiresAValue (spName, containerName, containerName, spName), m)) - | NonNull v -> v + | NonNull v -> { Name = spName; Value = v; ValueRange = range0; ValueRangeAdjusted = None } else error (Error(FSComp.SR.etStaticParameterRequiresAValue (spName, containerName, containerName, spName), m)) | ps -> diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index cb6bc023f86..fc16fcebac1 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1236,6 +1236,7 @@ invalidFullNameForProvidedType,"invalid full name for provided type" 3085,tcCustomOperationMayNotBeUsedInConjunctionWithNonSimpleLetBindings,"A custom operation may not be used in conjunction with a non-value or recursive 'let' binding in another part of this computation expression" 3086,tcCustomOperationMayNotBeUsedHere,"A custom operation may not be used in conjunction with 'use', 'try/with', 'try/finally', 'if/then/else' or 'match' operators within this computation expression" 3087,tcCustomOperationMayNotBeOverloaded,"The custom operation '%s' refers to a method which is overloaded. The implementations of custom operations may not be overloaded." +3088,etProviderWarning,"The type provider '%s' reported a warning: %s" featureOverloadsForCustomOperations,"overloads for custom operations" featureExpandedMeasurables,"more types support units of measure" featurePrintfBinaryFormat,"binary formatting for integers" diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 02f6fafd05d..999a2030dc4 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -19,6 +19,7 @@ open FSharp.Compiler.AbstractIL.IL open FSharp.Compiler.DiagnosticsLogger open FSharp.Compiler.Syntax open FSharp.Compiler.Text +open FSharp.Compiler.Text.Position open FSharp.Compiler.Text.Range type TypeProviderDesignation = TypeProviderDesignation of string @@ -412,8 +413,12 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = member _.GetGenericArguments() = x.GetGenericArguments() |> ProvidedType.CreateArray ctxt - member _.ApplyStaticArguments(provider: ITypeProvider, fullTypePathAfterArguments, staticArgs: obj[]) = - provider.ApplyStaticArguments(x, fullTypePathAfterArguments, staticArgs) |> ProvidedType.Create ctxt + member _.ApplyStaticArguments(provider: ITypeProvider, fullTypePathAfterArguments, staticArgs: obj[], diagnosticsContext: ITypeProviderDiagnosticsContext) = + match provider with + | (:? ITypeProvider3 as provider) -> + provider.ApplyStaticArguments(diagnosticsContext, x, fullTypePathAfterArguments, staticArgs) |> ProvidedType.Create ctxt + | _ -> + provider.ApplyStaticArguments(x, fullTypePathAfterArguments, staticArgs) |> ProvidedType.Create ctxt member _.IsVoid = (Type.op_Equality(x, typeof) || (x.Namespace = "System" && x.Name = "Void")) @@ -625,6 +630,36 @@ type ProvidedAssembly (x: Assembly) = override _.GetHashCode() = assert false; x.GetHashCode() +[] +type CrackedStaticArgument = { + Name: string + Value: obj + ValueRange: range + /// Range stripped of quotes if the argument is a string constant + ValueRangeAdjusted: range option +} + +type TypeProviderDiagnosticsContext (staticArgs: CrackedStaticArgument[], tpDesignation, fallbackRange) = + interface ITypeProviderDiagnosticsContext with + member _.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, severity) = + let m = + match staticArgs |> Array.tryFind (fun x -> x.Name = staticParameterName) with + | Some x when x.ValueRange <> range0 -> + match x.ValueRangeAdjusted, rangeInParameterIfString with + | Some m, Some (startPosition, endPosition) when startPosition < endPosition && startPosition >= 0 -> + // todo highlighted range spanning multiple lines :/ + mkFileIndexRange m.FileIndex (mkPos m.StartLine (m.StartColumn + startPosition)) (mkPos m.EndLine (m.StartColumn + endPosition)) + | _ -> + x.ValueRange + | _ -> + fallbackRange + + match severity with + | TypeProviderDiagnosticSeverity.Warning -> + Error (FSComp.SR.etProviderWarning (tpDesignation, message), m) |> warning + | TypeProviderDiagnosticSeverity.Error -> + stopProcessingRecovery (Error (FSComp.SR.etProviderError (tpDesignation, message), m)) m + [] type ProvidedMethodBase (x: MethodBase, ctxt) = inherit ProvidedMemberInfo(x, ctxt) @@ -686,15 +721,18 @@ type ProvidedMethodBase (x: MethodBase, ctxt) = staticParams |> ProvidedParameterInfo.CreateArray ctxt - member _.ApplyStaticArgumentsForMethod(provider: ITypeProvider, fullNameAfterArguments: string, staticArgs: obj[]) = + member _.ApplyStaticArgumentsForMethod(provider: ITypeProvider, fullNameAfterArguments: string, staticArgs: CrackedStaticArgument[], tpDesignation, m) = let bindingFlags = BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.InvokeMethod + let staticArgValues = staticArgs |> Array.map (fun x -> x.Value) let mb = match provider with + | :? ITypeProvider3 as itp3 -> + let ctx = TypeProviderDiagnosticsContext (staticArgs, tpDesignation, m) + itp3.ApplyStaticArgumentsForMethod(ctx, x, fullNameAfterArguments, staticArgValues) | :? ITypeProvider2 as itp2 -> - itp2.ApplyStaticArgumentsForMethod(x, fullNameAfterArguments, staticArgs) + itp2.ApplyStaticArgumentsForMethod(x, fullNameAfterArguments, staticArgValues) | _ -> - // To allow a type provider to depend only on FSharp.Core 4.3.0.0, it can alternatively implement a method called GetStaticParametersForMethod let meth = provider.GetType().GetMethod( "ApplyStaticArgumentsForMethod", bindingFlags, null, @@ -704,7 +742,7 @@ type ProvidedMethodBase (x: MethodBase, ctxt) = | null -> failwith (FSComp.SR.estApplyStaticArgumentsForMethodNotImplemented()) | _ -> let mbAsObj = - try meth.Invoke(provider, bindingFlags ||| BindingFlags.InvokeMethod, null, [| box x; box fullNameAfterArguments; box staticArgs |], null) + try meth.Invoke(provider, bindingFlags ||| BindingFlags.InvokeMethod, null, [| box x; box fullNameAfterArguments; box staticArgValues |], null) with err -> raise (StripException (StripException err)) match mbAsObj with @@ -1194,25 +1232,27 @@ let ILPathToProvidedType (st: Tainted, m) = encContrib st, nameContrib st -let ComputeMangledNameForApplyStaticParameters(nm, staticArgs, staticParams: Tainted, m) = +let ComputeMangledNameForApplyStaticParameters(nm, staticArgs: obj[], staticParams: Tainted, m) = let defaultArgValues = - staticParams.PApply((fun ps -> ps |> Array.map (fun sp -> sp.Name, (if sp.IsOptional then Some (string sp.RawDefaultValue) else None ))), range=m) + staticParams.PApply((fun ps -> ps |> Array.map (fun sp -> sp.Name, (if sp.IsOptional then Some (string sp.RawDefaultValue) else None ))), range = m) let defaultArgValues = defaultArgValues.PUntaint(id, m) PrettyNaming.ComputeMangledNameWithoutDefaultArgValues(nm, staticArgs, defaultArgValues) /// Apply the given provided method to the given static arguments (the arguments are assumed to have been sorted into application order) -let TryApplyProvidedMethod(methBeforeArgs: Tainted, staticArgs: obj[], m: range) = +let TryApplyProvidedMethod(methBeforeArgs: Tainted, staticArgs: CrackedStaticArgument[], m: range) = if staticArgs.Length = 0 then Some methBeforeArgs else + let staticArgValues = staticArgs |> Array.map (fun x -> x.Value) + let mangledName = let nm = methBeforeArgs.PUntaint((fun x -> x.Name), m) - let staticParams = methBeforeArgs.PApplyWithProvider((fun (mb, resolver) -> mb.GetStaticParametersForMethod resolver), range=m) - let mangledName = ComputeMangledNameForApplyStaticParameters(nm, staticArgs, staticParams, m) + let staticParams = methBeforeArgs.PApplyWithProvider((fun (mb, resolver) -> mb.GetStaticParametersForMethod resolver), range = m) + let mangledName = ComputeMangledNameForApplyStaticParameters(nm, staticArgValues, staticParams, m) mangledName - match methBeforeArgs.PApplyWithProvider((fun (mb, provider) -> mb.ApplyStaticArgumentsForMethod(provider, mangledName, staticArgs)), range=m) with + match methBeforeArgs.PApplyWithProvider((fun (mb, provider) -> mb.ApplyStaticArgumentsForMethod(provider, mangledName, staticArgs, methBeforeArgs.TypeProviderDesignation, m)), range = m) with | Tainted.Null -> None | Tainted.NonNull methWithArguments -> let actualName = methWithArguments.PUntaint((fun x -> x.Name), m) @@ -1220,12 +1260,12 @@ let TryApplyProvidedMethod(methBeforeArgs: Tainted, staticAr error(Error(FSComp.SR.etProvidedAppliedMethodHadWrongName(methWithArguments.TypeProviderDesignation, mangledName, actualName), m)) Some methWithArguments - /// Apply the given provided type to the given static arguments (the arguments are assumed to have been sorted into application order -let TryApplyProvidedType(typeBeforeArguments: Tainted, optGeneratedTypePath: string list option, staticArgs: obj[], m: range) = +let TryApplyProvidedType(typeBeforeArguments: Tainted, optGeneratedTypePath: string list option, staticArgs: CrackedStaticArgument[], m: range) = if staticArgs.Length = 0 then Some (typeBeforeArguments, (fun () -> ())) else + let staticArgValues = staticArgs |> Array.map (fun x -> x.Value) let fullTypePathAfterArguments = // If there is a generated type name, then use that @@ -1236,10 +1276,12 @@ let TryApplyProvidedType(typeBeforeArguments: Tainted, optGenerate let nm = typeBeforeArguments.PUntaint((fun x -> x.Name), m) let enc, _ = ILPathToProvidedType (typeBeforeArguments, m) let staticParams = typeBeforeArguments.PApplyWithProvider((fun (mb, resolver) -> mb.GetStaticParameters resolver), range=m) - let mangledName = ComputeMangledNameForApplyStaticParameters(nm, staticArgs, staticParams, m) + let mangledName = ComputeMangledNameForApplyStaticParameters(nm, staticArgValues, staticParams, m) enc @ [ mangledName ] + + let ctx = TypeProviderDiagnosticsContext (staticArgs, typeBeforeArguments.TypeProviderDesignation, m) - match typeBeforeArguments.PApplyWithProvider((fun (typeBeforeArguments, provider) -> typeBeforeArguments.ApplyStaticArguments(provider, Array.ofList fullTypePathAfterArguments, staticArgs)), range=m) with + match typeBeforeArguments.PApplyWithProvider((fun (typeBeforeArguments, provider) -> typeBeforeArguments.ApplyStaticArguments(provider, Array.ofList fullTypePathAfterArguments, staticArgValues, ctx)), range=m) with | Tainted.Null -> None | Tainted.NonNull typeWithArguments -> let actualName = typeWithArguments.PUntaint((fun x -> x.Name), m) @@ -1287,28 +1329,30 @@ let TryLinkProvidedType(resolver: Tainted, moduleOrNamespace: str let uet = if pt.IsEnum then pt.GetEnumUnderlyingType() else pt uet.FullName), range) - match spReprTypeName with - | "System.SByte" -> box (sbyte arg) - | "System.Int16" -> box (int16 arg) - | "System.Int32" -> box (int32 arg) - | "System.Int64" -> box (int64 arg) - | "System.Byte" -> box (byte arg) - | "System.UInt16" -> box (uint16 arg) - | "System.UInt32" -> box (uint32 arg) - | "System.UInt64" -> box (uint64 arg) - | "System.Decimal" -> box (decimal arg) - | "System.Single" -> box (single arg) - | "System.Double" -> box (double arg) - | "System.Char" -> box (char arg) - | "System.Boolean" -> box (arg = "True") - | "System.String" -> box (string arg) - | s -> error(Error(FSComp.SR.etUnknownStaticArgumentKind(s, typeLogicalName), range0)) - + let v = + match spReprTypeName with + | "System.SByte" -> box (sbyte arg) + | "System.Int16" -> box (int16 arg) + | "System.Int32" -> box (int32 arg) + | "System.Int64" -> box (int64 arg) + | "System.Byte" -> box (byte arg) + | "System.UInt16" -> box (uint16 arg) + | "System.UInt32" -> box (uint32 arg) + | "System.UInt64" -> box (uint64 arg) + | "System.Decimal" -> box (decimal arg) + | "System.Single" -> box (single arg) + | "System.Double" -> box (double arg) + | "System.Char" -> box (char arg) + | "System.Boolean" -> box (arg = "True") + | "System.String" -> box (string arg) + | s -> error(Error(FSComp.SR.etUnknownStaticArgumentKind(s, typeLogicalName), range0)) + + { Name = spName; Value = v; ValueRange = range0; ValueRangeAdjusted = None } | _ -> if sp.PUntaint ((fun sp -> sp.IsOptional), range) then match sp.PUntaint((fun sp -> sp.RawDefaultValue), range) with | Null -> error (Error(FSComp.SR.etStaticParameterRequiresAValue (spName, typeBeforeArgumentsName, typeBeforeArgumentsName, spName), range0)) - | NonNull v -> v + | NonNull v -> { Name = spName; Value = v; ValueRange = range0; ValueRangeAdjusted = None } else error(Error(FSComp.SR.etProvidedTypeReferenceMissingArgument spName, range0))) diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index b1e3ccaf85c..a8e9227ec63 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -439,6 +439,15 @@ type ProvidedVar = override GetHashCode: unit -> int +[] +type CrackedStaticArgument = { + Name: string + Value: obj + ValueRange: range + /// Range stripped of quotes if the argument is a string constant + ValueRangeAdjusted: range option +} + /// Get the provided expression for a particular use of a method. val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr @@ -450,12 +459,12 @@ val ValidateProvidedTypeAfterStaticInstantiation: /// to check the type name is as expected (this function is called by the caller of TryApplyProvidedType /// after other checks are made). val TryApplyProvidedType: - typeBeforeArguments: Tainted * optGeneratedTypePath: string list option * staticArgs: obj[] * range -> + typeBeforeArguments: Tainted * optGeneratedTypePath: string list option * staticArgs: CrackedStaticArgument[] * range -> (Tainted * (unit -> unit)) option /// Try to apply a provided method to the given static arguments. val TryApplyProvidedMethod: - methBeforeArgs: Tainted * staticArgs: obj[] * range -> Tainted option + methBeforeArgs: Tainted * staticArgs: CrackedStaticArgument[] * range -> Tainted option /// Try to resolve a type in the given extension type resolver val TryResolveProvidedType: Tainted * range * string[] * typeName: string -> Tainted option diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index a03a936bf42..72a470b3e50 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -132,6 +132,11 @@ Atribut sestavení {0} odkazuje na navržené sestavení {1}, které se nedá načíst nebo neexistuje. Ohlášená výjimka: {2} – {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions další převody orientované na typ diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 88d360b25a5..58887b80515 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -132,6 +132,11 @@ Das Assemblyattribut "{0}" verweist auf eine Designerassembly "{1}", die entweder nicht geladen werden kann oder nicht vorhanden ist. Gemeldete Ausnahme: {2} – {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions zusätzliche typgesteuerte Konvertierungen diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 02122ba6296..a1f53629320 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -132,6 +132,11 @@ El atributo de ensamblado "{0}" hace referencia a un ensamblado de diseñador "{1}" que no se puede cargar o no existe. Se notificó la excepción: {2} - {3}. + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions conversiones adicionales dirigidas a tipos diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 483f8b91ba7..2844939bcd0 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -132,6 +132,11 @@ L'attribut d'assembly '{0}' fait référence à un assembly de concepteur '{1}' qui ne peut pas être chargé ou qui n'existe pas. Exception signalée : {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions conversions supplémentaires dirigées vers le type diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 49cf9bad9b9..2a88cc99518 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -132,6 +132,11 @@ L'attributo di assembly '{0}' fa riferimento a un assembly '{1}' della finestra di progettazione che non è stato caricato o non esiste. L'eccezione restituita è {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions conversioni aggiuntive dirette ai tipi diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 0ed505a8718..9269cbac204 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -132,6 +132,11 @@ アセンブリ属性 '{0}' は、デザイナー アセンブリ '{1}' を参照していますが、これは読み込むことができないか、存在していません。報告された例外: {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions その他の型指定された変換 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 666a62143e2..572017ee2c3 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -132,6 +132,11 @@ '{0}' 어셈블리 특성이 로드할 수 없거나 존재하지 않는 디자이너 어셈블리'{1}'을(를) 참조합니다. 보고된 예외: {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions 추가 형식-디렉션 변환 diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 35f555a08b2..6f044ff12a8 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -132,6 +132,11 @@ Atrybut zestawu „{0}” odwołuje się do zestawu projektanta „{1}”, którego nie można załadować lub który nie istnieje. Zgłoszony wyjątek: {2} — {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions dodatkowe konwersje ukierunkowane na typ diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 7e4a20be7ac..43cccc57fd9 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -132,6 +132,11 @@ O atributo de assembly '{0}' refere-se a um assembly de designer '{1}' que não pode ser carregado ou que não existe. A exceção relatada foi {2} – {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions conversões direcionadas por tipos adicionais diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 4ab2847a189..fb179b44a4a 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -132,6 +132,11 @@ Атрибут сборки "{0}" ссылается на сборку конструктора "{1}", которая не может быть загружена или не существует. Получено исключение: {2} — {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions дополнительные преобразования на основе типа diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 85cca20423f..0dde917fd97 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -132,6 +132,11 @@ '{0}' bütünleştirilmiş kod özniteliği, yüklenemeyen veya mevcut olmayan '{1}' tasarımcı bütünleştirilmiş koduna başvuruyor. Bildirilen özel durum: {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions ek tür ile yönlendirilen dönüştürmeler diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 55f8ac8d9cd..a507dc05f60 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -132,6 +132,11 @@ 程序集属性“{0}”引用了无法加载或不存在的设计器程序集“{1}”。报告的异常是: {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions 附加类型定向转换 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 02122cbd5c2..99e9d17c314 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -132,6 +132,11 @@ 無法載入組件屬性 '{0}' 參考的設計工具組件 '{1}' 或其不存在。回報的例外狀況: {2} - {3} + + The type provider '{0}' reported a warning: {1} + The type provider '{0}' reported a warning: {1} + + additional type-directed conversions 其他類型導向轉換 diff --git a/src/FSharp.Core/fslib-extra-pervasives.fs b/src/FSharp.Core/fslib-extra-pervasives.fs index 01fd7018b11..8e9706bebd8 100644 --- a/src/FSharp.Core/fslib-extra-pervasives.fs +++ b/src/FSharp.Core/fslib-extra-pervasives.fs @@ -527,6 +527,15 @@ type IProvidedNamespace = abstract ResolveTypeName: typeName: string -> Type +[] +type TypeProviderDiagnosticSeverity = + | Warning + | Error + +[] +type ITypeProviderDiagnosticsContext = + abstract ReportDiagnostic: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * severity: TypeProviderDiagnosticSeverity -> unit + type ITypeProvider = inherit System.IDisposable @@ -549,3 +558,10 @@ type ITypeProvider2 = abstract ApplyStaticArgumentsForMethod: methodWithoutArguments: MethodBase * methodNameWithArguments: string * staticArguments: obj[] -> MethodBase + +type ITypeProvider3 = + abstract ApplyStaticArguments: + context: ITypeProviderDiagnosticsContext * typeWithoutArguments: Type * typePathWithArguments: string[] * staticArguments: obj[] -> Type + + abstract ApplyStaticArgumentsForMethod: + context: ITypeProviderDiagnosticsContext * methodWithoutArguments: MethodBase * methodNameWithArguments: string * staticArguments: obj[] -> MethodBase diff --git a/src/FSharp.Core/fslib-extra-pervasives.fsi b/src/FSharp.Core/fslib-extra-pervasives.fsi index ea1ec13f767..7910814e4fd 100644 --- a/src/FSharp.Core/fslib-extra-pervasives.fsi +++ b/src/FSharp.Core/fslib-extra-pervasives.fsi @@ -509,6 +509,15 @@ namespace Microsoft.FSharp.Core.CompilerServices /// abstract ResolveTypeName : typeName: string -> Type + [] + type TypeProviderDiagnosticSeverity = + | Warning + | Error + + [] + type ITypeProviderDiagnosticsContext = + abstract ReportDiagnostic: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * severity: TypeProviderDiagnosticSeverity -> unit + /// /// Represents an instantiation of a type provider component. /// @@ -585,3 +594,9 @@ namespace Microsoft.FSharp.Core.CompilerServices /// /// The provided method definition corresponding to the given static parameter values abstract ApplyStaticArgumentsForMethod : methodWithoutArguments:MethodBase * methodNameWithArguments:string * staticArguments:obj[] -> MethodBase + + type ITypeProvider3 = + abstract ApplyStaticArguments : context:ITypeProviderDiagnosticsContext * typeWithoutArguments:Type * typePathWithArguments:string[] * staticArguments:obj[] -> Type + + abstract ApplyStaticArgumentsForMethod: + context: ITypeProviderDiagnosticsContext * methodWithoutArguments: MethodBase * methodNameWithArguments: string * staticArguments: obj[] -> MethodBase diff --git a/tests/service/data/TestTP/ProvidedTypes.fs b/tests/service/data/TestTP/ProvidedTypes.fs index 4e7a7604c6b..f92662813fa 100644 --- a/tests/service/data/TestTP/ProvidedTypes.fs +++ b/tests/service/data/TestTP/ProvidedTypes.fs @@ -1075,22 +1075,42 @@ and ProvidedMethod(isTgt: bool, methodName: string, attrs: MethodAttributes, par member __.AddMethodAttrs attributes = attrs <- attrs ||| attributes member __.PatchDeclaringType x = patchOption declaringType (fun () -> declaringType <- Some x) - /// Abstract a type to a parametric-type. Requires "formal parameters" and "instantiation function". + member val private DiagnosticsContext: ITypeProviderDiagnosticsContext = null with get, set + + member x.ReportWarning (staticParameterName, rangeInParameterIfString, message, throwIfNotSupported) = + if isNull x.DiagnosticsContext |> not then + x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Warning) + elif throwIfNotSupported then + failwith message + + member x.ReportError (staticParameterName, rangeInParameterIfString, message) = + if isNull x.DiagnosticsContext then + failwith message + else + x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Error) + member __.DefineStaticParameters(parameters: ProvidedStaticParameter list, instantiationFunction: (string -> obj[] -> ProvidedMethod)) = staticParams <- parameters - staticParamsApply <- Some instantiationFunction + staticParamsApply <- Some (fun _this methodName staticArgs -> instantiationFunction methodName staticArgs) + + /// Abstract a type to a parametric-type. Requires "formal parameters" and "instantiation function". + member __.DefineStaticParameters(parameters: ProvidedStaticParameter list, instantiationFunction: (ProvidedMethod -> string -> obj[] -> ProvidedMethod)) = + staticParams <- parameters + staticParamsApply <- Some (fun this methodName staticArgs -> instantiationFunction this methodName staticArgs) /// Get ParameterInfo[] for the parametric type parameters member __.GetStaticParametersInternal() = [| for p in staticParams -> p :> ParameterInfo |] /// Instantiate parametric method - member this.ApplyStaticArguments(mangledName:string, args:obj[]) = + member this.ApplyStaticArguments(diagnosticsContext, mangledName:string, args:obj[]) = if staticParams.Length <> args.Length then failwithf "ProvidedMethod: expecting %d static parameters but given %d for method %s" staticParams.Length args.Length methodName if staticParams.Length > 0 then match staticParamsApply with | None -> failwith "ProvidedMethod: DefineStaticParameters was not called" - | Some f -> f mangledName args + | Some f -> + this.DiagnosticsContext <- diagnosticsContext + f this mangledName args else this @@ -9390,7 +9410,7 @@ namespace ProviderImplementation.ProvidedTypes x.ReturnType |> convTypeToTgt, x.GetInvokeCode |> Option.map (fun invokeCode -> convCodeToTgt (invokeCode, x.IsStatic, false, x.Parameters, not x.IsErased)), x.StaticParams |> List.map convStaticParameterDefToTgt, - x.StaticParamsApply |> Option.map (fun f s p -> f s p |> convProvidedMethodDefToTgt declTyT), + x.StaticParamsApply |> Option.map (fun f this s p -> f this s p |> convProvidedMethodDefToTgt declTyT), (x.GetCustomAttributesData >> convCustomAttributesDataToTgt)) :> _ | :? ProvidedTypeDefinition as x -> convTypeDefToTgt x :> _ | _ -> failwith "unknown member type" @@ -15864,6 +15884,20 @@ namespace ProviderImplementation.ProvidedTypes AppDomain.CurrentDomain.remove_AssemblyResolve handler #endif + member val private DiagnosticsContext: ITypeProviderDiagnosticsContext = null with get, set + + member x.ReportWarning (staticParameterName, rangeInParameterIfString, message, throwIfNotSupported) = + if isNull x.DiagnosticsContext |> not then + x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Warning) + elif throwIfNotSupported then + failwith message + + member x.ReportError (staticParameterName, rangeInParameterIfString, message) = + if isNull x.DiagnosticsContext then + failwith message + else + x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Error) + member __.AddNamespace (namespaceName, types) = namespacesT.Add (makeProvidedNamespace namespaceName types) @@ -15880,7 +15914,7 @@ namespace ProviderImplementation.ProvidedTypes member __.ApplyStaticArgumentsForMethod(mb: MethodBase, mangledName, objs) = match mb with - | :? ProvidedMethod as t -> t.ApplyStaticArguments(mangledName, objs) :> MethodBase + | :? ProvidedMethod as t -> t.ApplyStaticArguments(null, mangledName, objs) :> MethodBase | _ -> failwithf "ApplyStaticArguments: static parameters for method %s are unexpected. Please report this bug to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues" mb.Name interface ITypeProvider with @@ -15984,5 +16018,15 @@ namespace ProviderImplementation.ProvidedTypes theTable[key] <- assemblyBytes assembly + interface ITypeProvider3 with + member x.ApplyStaticArguments (diagnosticsContext, ty, typePathAfterArguments, objs) = + x.DiagnosticsContext <- diagnosticsContext + (x :> ITypeProvider).ApplyStaticArguments (ty, typePathAfterArguments, objs) + + member _.ApplyStaticArgumentsForMethod (diagnosticsContext, mb: MethodBase, mangledName, objs) = + match mb with + | :? ProvidedMethod as t -> t.ApplyStaticArguments(diagnosticsContext, mangledName, objs) :> MethodBase + | _ -> failwithf "ApplyStaticArguments: static parameters for method %s are unexpected. Please report this bug to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues" mb.Name + #endif #endif diff --git a/tests/service/data/TestTP/ProvidedTypes.fsi b/tests/service/data/TestTP/ProvidedTypes.fsi index 6f56c2e4e31..1279812129a 100644 --- a/tests/service/data/TestTP/ProvidedTypes.fsi +++ b/tests/service/data/TestTP/ProvidedTypes.fsi @@ -119,6 +119,12 @@ type ProvidedMethod = /// Define the static parameters available on a statically parameterized method member DefineStaticParameters: parameters: ProvidedStaticParameter list * instantiationFunction: (string -> obj[] -> ProvidedMethod) -> unit + member DefineStaticParameters: parameters: ProvidedStaticParameter list * instantiationFunction: (ProvidedMethod -> string -> obj[] -> ProvidedMethod) -> unit + + member ReportWarning: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * throwIfNotSupported: bool -> unit + + member ReportError: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string -> unit + /// This method is for internal use only in the type provider SDK member internal GetInvokeCode: (Expr list -> Expr) option @@ -522,8 +528,14 @@ type TypeProviderForNamespaces = /// the design-time context will normally be performed automatically. member TargetContext: ProvidedTypesContext + member ReportWarning: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * throwIfNotSupported: bool -> unit + + member ReportError: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string -> unit + interface ITypeProvider + interface ITypeProvider3 + module internal UncheckedQuotations = type Expr with diff --git a/tests/service/data/TestTP/TestTP.fs b/tests/service/data/TestTP/TestTP.fs index 4e7bf9dd092..9f97c50e23a 100644 --- a/tests/service/data/TestTP/TestTP.fs +++ b/tests/service/data/TestTP/TestTP.fs @@ -283,6 +283,25 @@ type BasicProvider (config : TypeProviderConfig) as this = invokeCode = fun args -> <@@ Helper.C.StaticAutoProperty <- 1; Helper.C.StaticAutoProperty @@>) myType.AddMember(someMethod) + let duplicatorParams = [ ProvidedParameter("c", typeof) ] + let duplicator = ProvidedMethod("Duplicator", duplicatorParams, typeof, isStatic = true) + duplicator.DefineStaticParameters( + [ + ProvidedStaticParameter("Length", typeof) + ], + fun this methodName (staticArgs: obj[]) -> + let count = unbox staticArgs[0] + + if count > 3 then + this.ReportWarning ("Length", None, "More than 3 not recommended.", false) + + let duplicate = ProvidedMethod(methodName, duplicatorParams, typeof, isStatic = true, invokeCode = (fun args -> <@@ System.String (%%args[0], count) @@>)) + myType.AddMember duplicate + duplicate + + ) + myType.AddMember duplicator + [myType] do @@ -295,10 +314,17 @@ type BasicGenerativeProvider (config : TypeProviderConfig) as this = let ns = "GeneratedWithConstructor.Provided" let asm = Assembly.GetExecutingAssembly() - let createType typeName (count:int) = + let createType typeName (count:int) (text: string) = let asm = ProvidedAssembly() let myType = ProvidedTypeDefinition(asm, ns, typeName, Some typeof, isErased=false) + if count > 5 then + this.ReportWarning ("Count", None, "More than 5 not recommended.", false) + + if text.Contains "tabl" then + let start = text.IndexOf "tabl" + this.ReportError ("Query", Some (start, start + 4), "Table does not exist.") + let ctor = ProvidedConstructor([], invokeCode = fun args -> <@@ "My internal state" :> obj @@>) myType.AddMember(ctor) @@ -311,13 +337,20 @@ type BasicGenerativeProvider (config : TypeProviderConfig) as this = let meth = ProvidedMethod("StaticMethod", [], typeof, isStatic=true, invokeCode = (fun args -> Expr.Value(null, typeof))) myType.AddMember(meth) + asm.AddTypes [ myType ] myType let myParamType = let t = ProvidedTypeDefinition(asm, ns, "GenerativeProvider", Some typeof, isErased=false) - t.DefineStaticParameters( [ProvidedStaticParameter("Count", typeof)], fun typeName args -> createType typeName (unbox args[0])) + t.DefineStaticParameters( + [ + ProvidedStaticParameter("Count", typeof) + ProvidedStaticParameter("Query", typeof) + ], + fun typeName args -> createType typeName (unbox args[0]) (unbox args[1])) + t do this.AddNamespace(ns, [myParamType]) From b7bc75d60b1fdbe51ea432ac887aa9878a917711 Mon Sep 17 00:00:00 2001 From: kerams Date: Tue, 3 Jan 2023 20:44:18 +0100 Subject: [PATCH 2/2] Add support for informational diagnostics --- src/Compiler/FSComp.txt | 1 + src/Compiler/TypedTree/TypeProviders.fs | 2 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 ++ src/FSharp.Core/fslib-extra-pervasives.fs | 2 +- src/FSharp.Core/fslib-extra-pervasives.fsi | 2 +- tests/service/data/TestTP/ProvidedTypes.fs | 52 ++++++++++++--------- tests/service/data/TestTP/ProvidedTypes.fsi | 4 ++ 19 files changed, 105 insertions(+), 23 deletions(-) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index fc16fcebac1..75f9ec66c60 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1237,6 +1237,7 @@ invalidFullNameForProvidedType,"invalid full name for provided type" 3086,tcCustomOperationMayNotBeUsedHere,"A custom operation may not be used in conjunction with 'use', 'try/with', 'try/finally', 'if/then/else' or 'match' operators within this computation expression" 3087,tcCustomOperationMayNotBeOverloaded,"The custom operation '%s' refers to a method which is overloaded. The implementations of custom operations may not be overloaded." 3088,etProviderWarning,"The type provider '%s' reported a warning: %s" +3089,etProviderInformational,"The type provider '%s' reported an informational warning: %s" featureOverloadsForCustomOperations,"overloads for custom operations" featureExpandedMeasurables,"more types support units of measure" featurePrintfBinaryFormat,"binary formatting for integers" diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 999a2030dc4..3c7b7be3a84 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -655,6 +655,8 @@ type TypeProviderDiagnosticsContext (staticArgs: CrackedStaticArgument[], tpDesi fallbackRange match severity with + | TypeProviderDiagnosticSeverity.Informational -> + Error (FSComp.SR.etProviderInformational (tpDesignation, message), m) |> informationalWarning | TypeProviderDiagnosticSeverity.Warning -> Error (FSComp.SR.etProviderWarning (tpDesignation, message), m) |> warning | TypeProviderDiagnosticSeverity.Error -> diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 72a470b3e50..01ca53c6686 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -132,6 +132,11 @@ Atribut sestavení {0} odkazuje na navržené sestavení {1}, které se nedá načíst nebo neexistuje. Ohlášená výjimka: {2} – {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 58887b80515..dca5def9803 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -132,6 +132,11 @@ Das Assemblyattribut "{0}" verweist auf eine Designerassembly "{1}", die entweder nicht geladen werden kann oder nicht vorhanden ist. Gemeldete Ausnahme: {2} – {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index a1f53629320..3446fb47f28 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -132,6 +132,11 @@ El atributo de ensamblado "{0}" hace referencia a un ensamblado de diseñador "{1}" que no se puede cargar o no existe. Se notificó la excepción: {2} - {3}. + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 2844939bcd0..2f912eef7fc 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -132,6 +132,11 @@ L'attribut d'assembly '{0}' fait référence à un assembly de concepteur '{1}' qui ne peut pas être chargé ou qui n'existe pas. Exception signalée : {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 2a88cc99518..7999655186e 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -132,6 +132,11 @@ L'attributo di assembly '{0}' fa riferimento a un assembly '{1}' della finestra di progettazione che non è stato caricato o non esiste. L'eccezione restituita è {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 9269cbac204..30cb1ffe8b0 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -132,6 +132,11 @@ アセンブリ属性 '{0}' は、デザイナー アセンブリ '{1}' を参照していますが、これは読み込むことができないか、存在していません。報告された例外: {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 572017ee2c3..362b4591a80 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -132,6 +132,11 @@ '{0}' 어셈블리 특성이 로드할 수 없거나 존재하지 않는 디자이너 어셈블리'{1}'을(를) 참조합니다. 보고된 예외: {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 6f044ff12a8..c25dbfe0aab 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -132,6 +132,11 @@ Atrybut zestawu „{0}” odwołuje się do zestawu projektanta „{1}”, którego nie można załadować lub który nie istnieje. Zgłoszony wyjątek: {2} — {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 43cccc57fd9..063bf710ae5 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -132,6 +132,11 @@ O atributo de assembly '{0}' refere-se a um assembly de designer '{1}' que não pode ser carregado ou que não existe. A exceção relatada foi {2} – {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index fb179b44a4a..c3a68deba83 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -132,6 +132,11 @@ Атрибут сборки "{0}" ссылается на сборку конструктора "{1}", которая не может быть загружена или не существует. Получено исключение: {2} — {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 0dde917fd97..48b3f5f03ac 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -132,6 +132,11 @@ '{0}' bütünleştirilmiş kod özniteliği, yüklenemeyen veya mevcut olmayan '{1}' tasarımcı bütünleştirilmiş koduna başvuruyor. Bildirilen özel durum: {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index a507dc05f60..6080683d59a 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -132,6 +132,11 @@ 程序集属性“{0}”引用了无法加载或不存在的设计器程序集“{1}”。报告的异常是: {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 99e9d17c314..9bbfdba0873 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -132,6 +132,11 @@ 無法載入組件屬性 '{0}' 參考的設計工具組件 '{1}' 或其不存在。回報的例外狀況: {2} - {3} + + The type provider '{0}' reported an informational warning: {1} + The type provider '{0}' reported an informational warning: {1} + + The type provider '{0}' reported a warning: {1} The type provider '{0}' reported a warning: {1} diff --git a/src/FSharp.Core/fslib-extra-pervasives.fs b/src/FSharp.Core/fslib-extra-pervasives.fs index 8e9706bebd8..98fa27b14b0 100644 --- a/src/FSharp.Core/fslib-extra-pervasives.fs +++ b/src/FSharp.Core/fslib-extra-pervasives.fs @@ -529,10 +529,10 @@ type IProvidedNamespace = [] type TypeProviderDiagnosticSeverity = + | Informational | Warning | Error -[] type ITypeProviderDiagnosticsContext = abstract ReportDiagnostic: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * severity: TypeProviderDiagnosticSeverity -> unit diff --git a/src/FSharp.Core/fslib-extra-pervasives.fsi b/src/FSharp.Core/fslib-extra-pervasives.fsi index 7910814e4fd..42909f5f409 100644 --- a/src/FSharp.Core/fslib-extra-pervasives.fsi +++ b/src/FSharp.Core/fslib-extra-pervasives.fsi @@ -511,10 +511,10 @@ namespace Microsoft.FSharp.Core.CompilerServices [] type TypeProviderDiagnosticSeverity = + | Informational | Warning | Error - [] type ITypeProviderDiagnosticsContext = abstract ReportDiagnostic: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * severity: TypeProviderDiagnosticSeverity -> unit diff --git a/tests/service/data/TestTP/ProvidedTypes.fs b/tests/service/data/TestTP/ProvidedTypes.fs index f92662813fa..4a68a5fb16c 100644 --- a/tests/service/data/TestTP/ProvidedTypes.fs +++ b/tests/service/data/TestTP/ProvidedTypes.fs @@ -1075,19 +1075,24 @@ and ProvidedMethod(isTgt: bool, methodName: string, attrs: MethodAttributes, par member __.AddMethodAttrs attributes = attrs <- attrs ||| attributes member __.PatchDeclaringType x = patchOption declaringType (fun () -> declaringType <- Some x) - member val private DiagnosticsContext: ITypeProviderDiagnosticsContext = null with get, set + member val private DiagnosticsContext: ITypeProviderDiagnosticsContext option = None with get, set + + member x.ReportInformational (staticParameterName, rangeInParameterIfString, message, throwIfNotSupported) = + match x.DiagnosticsContext with + | Some ctx -> ctx.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Informational) + | _ when throwIfNotSupported -> failwith message + | _ -> () member x.ReportWarning (staticParameterName, rangeInParameterIfString, message, throwIfNotSupported) = - if isNull x.DiagnosticsContext |> not then - x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Warning) - elif throwIfNotSupported then - failwith message + match x.DiagnosticsContext with + | Some ctx -> ctx.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Warning) + | _ when throwIfNotSupported -> failwith message + | _ -> () member x.ReportError (staticParameterName, rangeInParameterIfString, message) = - if isNull x.DiagnosticsContext then - failwith message - else - x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Error) + match x.DiagnosticsContext with + | Some ctx -> ctx.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Error) + | _ -> failwith message member __.DefineStaticParameters(parameters: ProvidedStaticParameter list, instantiationFunction: (string -> obj[] -> ProvidedMethod)) = staticParams <- parameters @@ -15884,19 +15889,24 @@ namespace ProviderImplementation.ProvidedTypes AppDomain.CurrentDomain.remove_AssemblyResolve handler #endif - member val private DiagnosticsContext: ITypeProviderDiagnosticsContext = null with get, set + member val private DiagnosticsContext: ITypeProviderDiagnosticsContext option = None with get, set + + member x.ReportInformational (staticParameterName, rangeInParameterIfString, message, throwIfNotSupported) = + match x.DiagnosticsContext with + | Some ctx -> ctx.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Informational) + | _ when throwIfNotSupported -> failwith message + | _ -> () member x.ReportWarning (staticParameterName, rangeInParameterIfString, message, throwIfNotSupported) = - if isNull x.DiagnosticsContext |> not then - x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Warning) - elif throwIfNotSupported then - failwith message + match x.DiagnosticsContext with + | Some ctx -> ctx.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Warning) + | _ when throwIfNotSupported -> failwith message + | _ -> () member x.ReportError (staticParameterName, rangeInParameterIfString, message) = - if isNull x.DiagnosticsContext then - failwith message - else - x.DiagnosticsContext.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Error) + match x.DiagnosticsContext with + | Some ctx -> ctx.ReportDiagnostic (staticParameterName, rangeInParameterIfString, message, TypeProviderDiagnosticSeverity.Error) + | _ -> failwith message member __.AddNamespace (namespaceName, types) = namespacesT.Add (makeProvidedNamespace namespaceName types) @@ -15914,7 +15924,7 @@ namespace ProviderImplementation.ProvidedTypes member __.ApplyStaticArgumentsForMethod(mb: MethodBase, mangledName, objs) = match mb with - | :? ProvidedMethod as t -> t.ApplyStaticArguments(null, mangledName, objs) :> MethodBase + | :? ProvidedMethod as t -> t.ApplyStaticArguments(None, mangledName, objs) :> MethodBase | _ -> failwithf "ApplyStaticArguments: static parameters for method %s are unexpected. Please report this bug to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues" mb.Name interface ITypeProvider with @@ -16020,12 +16030,12 @@ namespace ProviderImplementation.ProvidedTypes interface ITypeProvider3 with member x.ApplyStaticArguments (diagnosticsContext, ty, typePathAfterArguments, objs) = - x.DiagnosticsContext <- diagnosticsContext + x.DiagnosticsContext <- Some diagnosticsContext (x :> ITypeProvider).ApplyStaticArguments (ty, typePathAfterArguments, objs) member _.ApplyStaticArgumentsForMethod (diagnosticsContext, mb: MethodBase, mangledName, objs) = match mb with - | :? ProvidedMethod as t -> t.ApplyStaticArguments(diagnosticsContext, mangledName, objs) :> MethodBase + | :? ProvidedMethod as t -> t.ApplyStaticArguments(Some diagnosticsContext, mangledName, objs) :> MethodBase | _ -> failwithf "ApplyStaticArguments: static parameters for method %s are unexpected. Please report this bug to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues" mb.Name #endif diff --git a/tests/service/data/TestTP/ProvidedTypes.fsi b/tests/service/data/TestTP/ProvidedTypes.fsi index 1279812129a..f51bbfc71a2 100644 --- a/tests/service/data/TestTP/ProvidedTypes.fsi +++ b/tests/service/data/TestTP/ProvidedTypes.fsi @@ -121,6 +121,8 @@ type ProvidedMethod = member DefineStaticParameters: parameters: ProvidedStaticParameter list * instantiationFunction: (ProvidedMethod -> string -> obj[] -> ProvidedMethod) -> unit + member ReportInformational: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * throwIfNotSupported: bool -> unit + member ReportWarning: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * throwIfNotSupported: bool -> unit member ReportError: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string -> unit @@ -528,6 +530,8 @@ type TypeProviderForNamespaces = /// the design-time context will normally be performed automatically. member TargetContext: ProvidedTypesContext + member ReportInformational: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * throwIfNotSupported: bool -> unit + member ReportWarning: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string * throwIfNotSupported: bool -> unit member ReportError: staticParameterName: string * rangeInParameterIfString: (int * int) option * message: string -> unit