Skip to content

Commit 4fde5da

Browse files
authored
Type abbreviation mismatch extended data (#16811)
1 parent 04ddfad commit 4fde5da

38 files changed

+173
-71
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Add switch to generate types and members with IL visibility that accurately represents their F# visibility. ([PR #15484](https://github.com/dotnet/fsharp/pull/15484)
2727
* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473))
2828
* Symbols: Add GenericArguments to FSharpEntity ([PR #16470](https://github.com/dotnet/fsharp/pull/16470))
29+
* Add extended data for `DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer` (FS0318). ([PR #16811](https://github.com/dotnet/fsharp/pull/16811)))
2930

3031
### Changed
3132

src/Compiler/Checking/SignatureConformance.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ exception InterfaceNotRevealed of DisplayEnv * TType * range
3939

4040
exception ArgumentsInSigAndImplMismatch of sigArg: Ident * implArg: Ident
4141

42+
exception DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer of
43+
denv: DisplayEnv *
44+
implTycon:Tycon *
45+
sigTycon:Tycon *
46+
implTypeAbbrev:TType *
47+
sigTypeAbbrev:TType *
48+
range: range
49+
4250
// Use a type to capture the constant, common parameters
4351
type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
4452

@@ -589,8 +597,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
589597
match implTycon.TypeAbbrev, sigTycon.TypeAbbrev with
590598
| Some ty1, Some ty2 ->
591599
if not (typeAEquiv g aenv ty1 ty2) then
592-
let s1, s2, _ = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
593-
errorR (Error (FSComp.SR.DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(implTycon.TypeOrMeasureKind.ToString(), implTycon.DisplayName, s1, s2), m))
600+
errorR (DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(denv, implTycon, sigTycon, ty1, ty2, m))
594601
false
595602
else
596603
true

src/Compiler/Checking/SignatureConformance.fsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ exception InterfaceNotRevealed of DisplayEnv * TType * range
4040

4141
exception ArgumentsInSigAndImplMismatch of sigArg: Ident * implArg: Ident
4242

43+
exception DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer of
44+
denv: DisplayEnv *
45+
implTycon: Tycon *
46+
sigTycon: Tycon *
47+
implTypeAbbrev: TType *
48+
sigTypeAbbrev: TType *
49+
range: range
50+
4351
type Checker =
4452

4553
new:

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type Exception with
7979

8080
member exn.DiagnosticRange =
8181
match exn with
82+
| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(range = m) -> Some m
8283
| ArgumentsInSigAndImplMismatch(_, implArg) -> Some implArg.idRange
8384
| ErrorFromAddingConstraint(_, exn2, _) -> exn2.DiagnosticRange
8485
#if !NO_TYPEPROVIDERS
@@ -320,22 +321,24 @@ type Exception with
320321
| BadEventTransformation _ -> 91
321322
| HashLoadedScriptConsideredSource _ -> 92
322323
| UnresolvedConversionOperator _ -> 93
323-
| ArgumentsInSigAndImplMismatch _ -> 3218
324+
324325
// avoid 94-100 for safety
325326
| ObsoleteError _ -> 101
326327
#if !NO_TYPEPROVIDERS
327328
| TypeProviders.ProvidedTypeResolutionNoRange _
328329
| TypeProviders.ProvidedTypeResolution _ -> 103
329330
#endif
330331
| PatternMatchCompilation.EnumMatchIncomplete _ -> 104
332+
| Failure _ -> 192
333+
| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer _ -> 318
334+
| ArgumentsInSigAndImplMismatch _ -> 3218
331335

332336
// Strip TargetInvocationException wrappers
333337
| :? TargetInvocationException as e -> e.InnerException.DiagnosticNumber
334338
| WrappedError(e, _) -> e.DiagnosticNumber
335339
| DiagnosticWithText(n, _, _) -> n
336340
| DiagnosticWithSuggestions(n, _, _, _, _) -> n
337341
| DiagnosticEnabledWithLanguageFeature(n, _, _, _) -> n
338-
| Failure _ -> 192
339342
| IllegalFileNameChar(fileName, invalidChar) -> fst (FSComp.SR.buildUnexpectedFileNameCharacter (fileName, string invalidChar))
340343
#if !NO_TYPEPROVIDERS
341344
| :? TypeProviderError as e -> e.Number
@@ -606,6 +609,9 @@ module OldStyleMessages =
606609
let TargetInvocationExceptionWrapperE () = Message("TargetInvocationExceptionWrapper", "%s")
607610
let ArgumentsInSigAndImplMismatchE () = Message("ArgumentsInSigAndImplMismatch", "%s%s")
608611

612+
let DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferE () =
613+
Message("DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer", "%s%s%s%s")
614+
609615
#if DEBUG
610616
let mutable showParserStackOnParseError = false
611617
#endif
@@ -1857,6 +1863,17 @@ type Exception with
18571863
| ArgumentsInSigAndImplMismatch(sigArg, implArg) ->
18581864
os.AppendString(ArgumentsInSigAndImplMismatchE().Format sigArg.idText implArg.idText)
18591865

1866+
| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(denv, implTycon, _sigTycon, implTypeAbbrev, sigTypeAbbrev, _m) ->
1867+
let s1, s2, _ = NicePrint.minimalStringsOfTwoTypes denv implTypeAbbrev sigTypeAbbrev
1868+
1869+
os.AppendString(
1870+
DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferE().Format
1871+
(implTycon.TypeOrMeasureKind.ToString())
1872+
implTycon.DisplayName
1873+
s1
1874+
s2
1875+
)
1876+
18601877
// Strip TargetInvocationException wrappers
18611878
| :? TargetInvocationException as exn -> exn.InnerException.Output(os, suggestNames)
18621879

src/Compiler/FSComp.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ ValueNotContainedMutabilityInstanceButStatic,"Module '%s' contains\n %s \n
155155
315,DefinitionsInSigAndImplNotCompatibleAbstractMemberMissingInImpl,"The %s definitions for type '%s' in the signature and implementation are not compatible because the abstract member '%s' was required by the signature but was not specified by the implementation"
156156
316,DefinitionsInSigAndImplNotCompatibleAbstractMemberMissingInSig,"The %s definitions for type '%s' in the signature and implementation are not compatible because the abstract member '%s' was present in the implementation but not in the signature"
157157
317,DefinitionsInSigAndImplNotCompatibleSignatureDeclaresDiffer,"The %s definitions for type '%s' in the signature and implementation are not compatible because the signature declares a %s while the implementation declares a %s"
158-
318,DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer,"The %s definitions for type '%s' in the signature and implementation are not compatible because the abbreviations differ: %s versus %s"
159158
319,DefinitionsInSigAndImplNotCompatibleAbbreviationHiddenBySig,"The %s definitions for type '%s' in the signature and implementation are not compatible because an abbreviation is being hidden by a signature. The abbreviation must be visible to other CLI languages. Consider making the abbreviation visible in the signature."
160159
320,DefinitionsInSigAndImplNotCompatibleSigHasAbbreviation,"The %s definitions for type '%s' in the signature and implementation are not compatible because the signature has an abbreviation while the implementation does not"
161160
ModuleContainsConstructorButNamesDiffer,"The module contains the constructor\n %s \nbut its signature specifies\n %s \nThe names differ"

src/Compiler/FSStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@
11131113
<data name="ArgumentsInSigAndImplMismatch" xml:space="preserve">
11141114
<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>
11151115
</data>
1116+
<data name="DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer" xml:space="preserve">
1117+
<value>The {0} definitions for type '{1}' in the signature and implementation are not compatible because the abbreviations differ:\n {2}\nversus\n {3}</value>
1118+
</data>
11161119
<data name="Parser.TOKEN.WHILE.BANG" xml:space="preserve">
11171120
<value>keyword 'while!'</value>
11181121
</data>

src/Compiler/Symbols/FSharpDiagnostic.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ module ExtendedData =
106106
member x.ImplementationName = implArg.idText
107107
member x.SignatureRange = sigArg.idRange
108108
member x.ImplementationRange = implArg.idRange
109+
110+
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
111+
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData
112+
internal(signatureType: Tycon, implementationType: Tycon) =
113+
interface IFSharpDiagnosticExtendedData
114+
member x.SignatureRange: range = signatureType.Range
115+
member x.ImplementationRange: range = implementationType.Range
109116

110117
open ExtendedData
111118

@@ -191,6 +198,9 @@ type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: str
191198
| ArgumentsInSigAndImplMismatch(sigArg, implArg) ->
192199
Some(ArgumentsInSigAndImplMismatchExtendedData(sigArg, implArg))
193200

201+
| DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer(implTycon = implTycon; sigTycon = sigTycon) ->
202+
Some(DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData(sigTycon, implTycon))
203+
194204
| _ -> None
195205

196206
let msg =

src/Compiler/Symbols/FSharpDiagnostic.fsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ module public ExtendedData =
101101
/// Argument identifier range within implementation file
102102
member ImplementationRange: range
103103

104+
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
105+
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData =
106+
interface IFSharpDiagnosticExtendedData
107+
/// Range of the signature type identifier.
108+
member SignatureRange: range
109+
/// Range of the implementation type identifier.
110+
member ImplementationRange: range
111+
104112
open ExtendedData
105113

106114
/// Represents a diagnostic produced by the F# compiler

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)