-
Notifications
You must be signed in to change notification settings - Fork 790
/
CompileOps.fs
5330 lines (4762 loc) · 284 KB
/
CompileOps.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// Coordinating compiler operations - configuration, loading initial context, reporting errors etc.
module internal Microsoft.FSharp.Compiler.CompileOps
open System
open System.Text
open System.IO
open System.Collections.Generic
open System.Runtime.CompilerServices
open Internal.Utilities
open Internal.Utilities.Text
open Internal.Utilities.Collections
open Internal.Utilities.Filename
open Microsoft.FSharp.Compiler.AbstractIL
open Microsoft.FSharp.Compiler.AbstractIL.IL
open Microsoft.FSharp.Compiler.AbstractIL.Internal
open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
open Microsoft.FSharp.Compiler.AbstractIL.Extensions.ILX
open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.TastPickle
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.TypeChecker
open Microsoft.FSharp.Compiler.SR
open Microsoft.FSharp.Compiler.DiagnosticMessage
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.Ast
open Microsoft.FSharp.Compiler.AttributeChecking
open Microsoft.FSharp.Compiler.ErrorLogger
open Microsoft.FSharp.Compiler.Tast
open Microsoft.FSharp.Compiler.Tastops
open Microsoft.FSharp.Compiler.Tastops.DebugPrint
open Microsoft.FSharp.Compiler.TcGlobals
open Microsoft.FSharp.Compiler.Lexhelp
open Microsoft.FSharp.Compiler.Lib
open Microsoft.FSharp.Compiler.Infos
open Microsoft.FSharp.Compiler.ConstraintSolver
open Microsoft.FSharp.Compiler.ReferenceResolver
open Microsoft.FSharp.Compiler.TypeRelations
open Microsoft.FSharp.Compiler.SignatureConformance
open Microsoft.FSharp.Compiler.MethodOverrides
open Microsoft.FSharp.Compiler.NameResolution
open Microsoft.FSharp.Compiler.PrettyNaming
open Microsoft.FSharp.Compiler.Import
#if EXTENSIONTYPING
open Microsoft.FSharp.Compiler.ExtensionTyping
open Microsoft.FSharp.Core.CompilerServices
#endif
#if FX_RESHAPED_REFLECTION
open Microsoft.FSharp.Core.ReflectionAdapters
#endif
#if DEBUG
#if COMPILED_AS_LANGUAGE_SERVICE_DLL
module internal CompilerService =
#else
module internal FullCompiler =
#endif
let showAssertForUnexpectedException = ref true
#if COMPILED_AS_LANGUAGE_SERVICE_DLL
open CompilerService
#else
open FullCompiler
#endif
#endif
//----------------------------------------------------------------------------
// Some Globals
//--------------------------------------------------------------------------
let FSharpSigFileSuffixes = [".mli";".fsi"]
let mlCompatSuffixes = [".mli";".ml"]
let FSharpImplFileSuffixes = [".ml";".fs";".fsscript";".fsx"]
let resSuffixes = [".resx"]
let FSharpScriptFileSuffixes = [".fsscript";".fsx"]
let doNotRequireNamespaceOrModuleSuffixes = [".mli";".ml"] @ FSharpScriptFileSuffixes
let FSharpLightSyntaxFileSuffixes : string list = [ ".fs";".fsscript";".fsx";".fsi" ]
//----------------------------------------------------------------------------
// ERROR REPORTING
//--------------------------------------------------------------------------
exception HashIncludeNotAllowedInNonScript of range
exception HashReferenceNotAllowedInNonScript of range
exception HashDirectiveNotAllowedInNonScript of range
exception FileNameNotResolved of (*filename*) string * (*description of searched locations*) string * range
exception AssemblyNotResolved of (*originalName*) string * range
exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
exception MSBuildReferenceResolutionWarning of (*MSBuild warning code*)string * (*Message*)string * range
exception MSBuildReferenceResolutionError of (*MSBuild warning code*)string * (*Message*)string * range
exception DeprecatedCommandLineOptionFull of string * range
exception DeprecatedCommandLineOptionForHtmlDoc of string * range
exception DeprecatedCommandLineOptionSuggestAlternative of string * string * range
exception DeprecatedCommandLineOptionNoDescription of string * range
exception InternalCommandLineOption of string * range
exception HashLoadedSourceHasIssues of (*warnings*) exn list * (*errors*) exn list * range
exception HashLoadedScriptConsideredSource of range
let GetRangeOfDiagnostic(err:PhasedDiagnostic) =
let rec RangeFromException = function
| ErrorFromAddingConstraint(_,err2,_) -> RangeFromException err2
#if EXTENSIONTYPING
| ExtensionTyping.ProvidedTypeResolutionNoRange(e) -> RangeFromException e
| ExtensionTyping.ProvidedTypeResolution(m,_)
#endif
| ReservedKeyword(_,m)
| IndentationProblem(_,m)
| ErrorFromAddingTypeEquation(_,_,_,_,_,m)
| ErrorFromApplyingDefault(_,_,_,_,_,m)
| ErrorsFromAddingSubsumptionConstraint(_,_,_,_,_,_,m)
| FunctionExpected(_,_,m)
| BakedInMemberConstraintName(_,m)
| StandardOperatorRedefinitionWarning(_,m)
| BadEventTransformation(m)
| ParameterlessStructCtor(m)
| FieldNotMutable (_,_,m)
| Recursion (_,_,_,_,m)
| InvalidRuntimeCoercion(_,_,_,m)
| IndeterminateRuntimeCoercion(_,_,_,m)
| IndeterminateStaticCoercion (_,_,_,m)
| StaticCoercionShouldUseBox (_,_,_,m)
| CoercionTargetSealed(_,_,m)
| UpcastUnnecessary(m)
| QuotationTranslator.IgnoringPartOfQuotedTermWarning (_,m)
| TypeTestUnnecessary(m)
| RuntimeCoercionSourceSealed(_,_,m)
| OverrideDoesntOverride(_,_,_,_,_,m)
| UnionPatternsBindDifferentNames m
| UnionCaseWrongArguments (_,_,_,m)
| TypeIsImplicitlyAbstract m
| RequiredButNotSpecified (_,_,_,_,m)
| FunctionValueUnexpected (_,_,m)
| UnitTypeExpected (_,_,m)
| UnitTypeExpectedWithEquality (_,_,m)
| UnitTypeExpectedWithPossiblePropertySetter (_,_,_,_,m)
| UnitTypeExpectedWithPossibleAssignment (_,_,_,_,m)
| UseOfAddressOfOperator m
| DeprecatedThreadStaticBindingWarning(m)
| NonUniqueInferredAbstractSlot (_,_,_,_,_,m)
| DefensiveCopyWarning (_,m)
| LetRecCheckedAtRuntime m
| UpperCaseIdentifierInPattern m
| NotUpperCaseConstructor m
| RecursiveUseCheckedAtRuntime (_,_,m)
| LetRecEvaluatedOutOfOrder (_,_,_,m)
| Error (_,m)
| ErrorWithSuggestions (_,m,_,_)
| NumberedError (_,m)
| SyntaxError (_,m)
| InternalError (_,m)
| FullAbstraction(_,m)
| InterfaceNotRevealed(_,_,m)
| WrappedError (_,m)
| PatternMatchCompilation.MatchIncomplete (_,_,m)
| PatternMatchCompilation.RuleNeverMatched m
| ValNotMutable(_,_,m)
| ValNotLocal(_,_,m)
| MissingFields(_,m)
| OverrideInIntrinsicAugmentation(m)
| IntfImplInIntrinsicAugmentation(m)
| OverrideInExtrinsicAugmentation(m)
| IntfImplInExtrinsicAugmentation(m)
| ValueRestriction(_,_,_,_,m)
| LetRecUnsound (_,_,m)
| ObsoleteError (_,m)
| ObsoleteWarning (_,m)
| Experimental (_,m)
| PossibleUnverifiableCode m
| UserCompilerMessage (_,_,m)
| Deprecated(_,m)
| LibraryUseOnly(m)
| FieldsFromDifferentTypes (_,_,_,m)
| IndeterminateType(m)
| TyconBadArgs(_,_,_,m) ->
Some m
| FieldNotContained(_,arf,_,_) -> Some arf.Range
| ValueNotContained(_,_,aval,_,_) -> Some aval.Range
| ConstrNotContained(_,aval,_,_) -> Some aval.Id.idRange
| ExnconstrNotContained(_,aexnc,_,_) -> Some aexnc.Range
| VarBoundTwice(id)
| UndefinedName(_,_,id,_) ->
Some id.idRange
| Duplicate(_,_,m)
| NameClash(_,_,_,m,_,_,_)
| UnresolvedOverloading(_,_,_,m)
| UnresolvedConversionOperator (_,_,_,m)
| PossibleOverload(_,_,_, m)
| VirtualAugmentationOnNullValuedType(m)
| NonVirtualAugmentationOnNullValuedType(m)
| NonRigidTypar(_,_,_,_,_,m)
| ConstraintSolverTupleDiffLengths(_,_,_,m,_)
| ConstraintSolverInfiniteTypes(_,_,_,_,m,_)
| ConstraintSolverMissingConstraint(_,_,_,m,_)
| ConstraintSolverTypesNotInEqualityRelation(_,_,_,m,_,_)
| ConstraintSolverError(_,m,_)
| ConstraintSolverTypesNotInSubsumptionRelation(_,_,_,m,_)
| ConstraintSolverRelatedInformation(_,m,_)
| SelfRefObjCtor(_,m) ->
Some m
| NotAFunction(_,_,mfun,_) ->
Some mfun
| IllegalFileNameChar(_) -> Some rangeCmdArgs
| UnresolvedReferenceError(_,m)
| UnresolvedPathReference(_,_,m)
| DeprecatedCommandLineOptionFull(_,m)
| DeprecatedCommandLineOptionForHtmlDoc(_,m)
| DeprecatedCommandLineOptionSuggestAlternative(_,_,m)
| DeprecatedCommandLineOptionNoDescription(_,m)
| InternalCommandLineOption(_,m)
| HashIncludeNotAllowedInNonScript(m)
| HashReferenceNotAllowedInNonScript(m)
| HashDirectiveNotAllowedInNonScript(m)
| FileNameNotResolved(_,_,m)
| LoadedSourceNotFoundIgnoring(_,m)
| MSBuildReferenceResolutionWarning(_,_,m)
| MSBuildReferenceResolutionError(_,_,m)
| AssemblyNotResolved(_,m)
| HashLoadedSourceHasIssues(_,_,m)
| HashLoadedScriptConsideredSource(m) ->
Some m
// Strip TargetInvocationException wrappers
| :? System.Reflection.TargetInvocationException as e ->
RangeFromException e.InnerException
#if EXTENSIONTYPING
| :? TypeProviderError as e -> e.Range |> Some
#endif
| _ -> None
RangeFromException err.Exception
let GetDiagnosticNumber(err:PhasedDiagnostic) =
let rec GetFromException(e:exn) =
match e with
(* DO NOT CHANGE THESE NUMBERS *)
| ErrorFromAddingTypeEquation _ -> 1
| FunctionExpected _ -> 2
| NotAFunction _ -> 3
| FieldNotMutable _ -> 5
| Recursion _ -> 6
| InvalidRuntimeCoercion _ -> 7
| IndeterminateRuntimeCoercion _ -> 8
| PossibleUnverifiableCode _ -> 9
| SyntaxError _ -> 10
// 11 cannot be reused
// 12 cannot be reused
| IndeterminateStaticCoercion _ -> 13
| StaticCoercionShouldUseBox _ -> 14
// 15 cannot be reused
| RuntimeCoercionSourceSealed _ -> 16
| OverrideDoesntOverride _ -> 17
| UnionPatternsBindDifferentNames _ -> 18
| UnionCaseWrongArguments _ -> 19
| UnitTypeExpected _ -> 20
| UnitTypeExpectedWithEquality _ -> 20
| UnitTypeExpectedWithPossiblePropertySetter _ -> 20
| UnitTypeExpectedWithPossibleAssignment _ -> 20
| RecursiveUseCheckedAtRuntime _ -> 21
| LetRecEvaluatedOutOfOrder _ -> 22
| NameClash _ -> 23
// 24 cannot be reused
| PatternMatchCompilation.MatchIncomplete _ -> 25
| PatternMatchCompilation.RuleNeverMatched _ -> 26
| ValNotMutable _ -> 27
| ValNotLocal _ -> 28
| MissingFields _ -> 29
| ValueRestriction _ -> 30
| LetRecUnsound _ -> 31
| FieldsFromDifferentTypes _ -> 32
| TyconBadArgs _ -> 33
| ValueNotContained _ -> 34
| Deprecated _ -> 35
| ConstrNotContained _ -> 36
| Duplicate _ -> 37
| VarBoundTwice _ -> 38
| UndefinedName _ -> 39
| LetRecCheckedAtRuntime _ -> 40
| UnresolvedOverloading _ -> 41
| LibraryUseOnly _ -> 42
| ErrorFromAddingConstraint _ -> 43
| ObsoleteWarning _ -> 44
| FullAbstraction _ -> 45
| ReservedKeyword _ -> 46
| SelfRefObjCtor _ -> 47
| VirtualAugmentationOnNullValuedType _ -> 48
| UpperCaseIdentifierInPattern _ -> 49
| InterfaceNotRevealed _ -> 50
| UseOfAddressOfOperator _ -> 51
| DefensiveCopyWarning _ -> 52
| NotUpperCaseConstructor _ -> 53
| TypeIsImplicitlyAbstract _ -> 54
// 55 cannot be reused
| DeprecatedThreadStaticBindingWarning _ -> 56
| Experimental _ -> 57
| IndentationProblem _ -> 58
| CoercionTargetSealed _ -> 59
| OverrideInIntrinsicAugmentation _ -> 60
| NonVirtualAugmentationOnNullValuedType _ -> 61
| UserCompilerMessage (_,n,_) -> n
| ExnconstrNotContained _ -> 63
| NonRigidTypar _ -> 64
// 65 cannot be reused
| UpcastUnnecessary _ -> 66
| TypeTestUnnecessary _ -> 67
| QuotationTranslator.IgnoringPartOfQuotedTermWarning _ -> 68
| IntfImplInIntrinsicAugmentation _ -> 69
| NonUniqueInferredAbstractSlot _ -> 70
| ErrorFromApplyingDefault _ -> 71
| IndeterminateType _ -> 72
| InternalError _ -> 73
| UnresolvedReferenceNoRange _
| UnresolvedReferenceError _
| UnresolvedPathReferenceNoRange _
| UnresolvedPathReference _ -> 74
| DeprecatedCommandLineOptionFull _
| DeprecatedCommandLineOptionForHtmlDoc _
| DeprecatedCommandLineOptionSuggestAlternative _
| DeprecatedCommandLineOptionNoDescription _
| InternalCommandLineOption _ -> 75
| HashIncludeNotAllowedInNonScript _
| HashReferenceNotAllowedInNonScript _
| HashDirectiveNotAllowedInNonScript _ -> 76
| BakedInMemberConstraintName _ -> 77
| FileNameNotResolved _ -> 78
| LoadedSourceNotFoundIgnoring _ -> 79
// 80 cannot be reused
| ParameterlessStructCtor _ -> 81
| MSBuildReferenceResolutionWarning _ -> 82
| MSBuildReferenceResolutionError _ -> 83
| AssemblyNotResolved _ -> 84
| HashLoadedSourceHasIssues _ -> 85
| StandardOperatorRedefinitionWarning _ -> 86
| InvalidInternalsVisibleToAssemblyName _ -> 87
// 88 cannot be reused
| OverrideInExtrinsicAugmentation _ -> 89
| IntfImplInExtrinsicAugmentation _ -> 90
| BadEventTransformation _ -> 91
| HashLoadedScriptConsideredSource _ -> 92
| UnresolvedConversionOperator _ -> 93
// avoid 94-100 for safety
| ObsoleteError _ -> 101
#if EXTENSIONTYPING
| ExtensionTyping.ProvidedTypeResolutionNoRange _
| ExtensionTyping.ProvidedTypeResolution _ -> 103
#endif
(* DO NOT CHANGE THE NUMBERS *)
// Strip TargetInvocationException wrappers
| :? System.Reflection.TargetInvocationException as e ->
GetFromException e.InnerException
| WrappedError(e,_) -> GetFromException e
| Error ((n,_),_) -> n
| ErrorWithSuggestions ((n,_),_,_,_) -> n
| Failure _ -> 192
| NumberedError((n,_),_) -> n
| IllegalFileNameChar(fileName,invalidChar) -> fst (FSComp.SR.buildUnexpectedFileNameCharacter(fileName,string invalidChar))
#if EXTENSIONTYPING
| :? TypeProviderError as e -> e.Number
#endif
| ErrorsFromAddingSubsumptionConstraint (_,_,_,_,_,ContextInfo.DowncastUsedInsteadOfUpcast _,_) -> fst (FSComp.SR.considerUpcast("",""))
| _ -> 193
GetFromException err.Exception
let GetWarningLevel err =
match err.Exception with
// Level 5 warnings
| RecursiveUseCheckedAtRuntime _
| LetRecEvaluatedOutOfOrder _
| DefensiveCopyWarning _
| FullAbstraction _ -> 5
| NumberedError((n,_),_)
| ErrorWithSuggestions((n,_),_,_,_)
| Error((n,_),_) ->
// 1178,tcNoComparisonNeeded1,"The struct, record or union type '%s' is not structurally comparable because the type parameter %s does not satisfy the 'comparison' constraint. Consider adding the 'NoComparison' attribute to this type to clarify that the type is not comparable"
// 1178,tcNoComparisonNeeded2,"The struct, record or union type '%s' is not structurally comparable because the type '%s' does not satisfy the 'comparison' constraint. Consider adding the 'NoComparison' attribute to this type to clarify that the type is not comparable"
// 1178,tcNoEqualityNeeded1,"The struct, record or union type '%s' does not support structural equality because the type parameter %s does not satisfy the 'equality' constraint. Consider adding the 'NoEquality' attribute to this type to clarify that the type does not support structural equality"
// 1178,tcNoEqualityNeeded2,"The struct, record or union type '%s' does not support structural equality because the type '%s' does not satisfy the 'equality' constraint. Consider adding the 'NoEquality' attribute to this type to clarify that the type does not support structural equality"
if (n = 1178) then 5 else 2
// Level 2
| _ -> 2
let warningOn err level specificWarnOn =
let n = GetDiagnosticNumber err
List.contains n specificWarnOn ||
// Some specific warnings are never on by default, i.e. unused variable warnings
match n with
| 1182 -> false // chkUnusedValue - off by default
| 3180 -> false // abImplicitHeapAllocation - off by default
| _ -> level >= GetWarningLevel err
let SplitRelatedDiagnostics(err:PhasedDiagnostic) =
let ToPhased(e) = {Exception=e; Phase = err.Phase}
let rec SplitRelatedException = function
| UnresolvedOverloading(a,overloads,b,c) ->
let related = overloads |> List.map ToPhased
UnresolvedOverloading(a,[],b,c)|>ToPhased, related
| ConstraintSolverRelatedInformation(fopt,m2,e) ->
let e,related = SplitRelatedException e
ConstraintSolverRelatedInformation(fopt,m2,e.Exception)|>ToPhased, related
| ErrorFromAddingTypeEquation(g,denv,t1,t2,e,m) ->
let e,related = SplitRelatedException e
ErrorFromAddingTypeEquation(g,denv,t1,t2,e.Exception,m)|>ToPhased, related
| ErrorFromApplyingDefault(g,denv,tp,defaultType,e,m) ->
let e,related = SplitRelatedException e
ErrorFromApplyingDefault(g,denv,tp,defaultType,e.Exception,m)|>ToPhased, related
| ErrorsFromAddingSubsumptionConstraint(g,denv,t1,t2,e,contextInfo,m) ->
let e,related = SplitRelatedException e
ErrorsFromAddingSubsumptionConstraint(g,denv,t1,t2,e.Exception,contextInfo,m)|>ToPhased, related
| ErrorFromAddingConstraint(x,e,m) ->
let e,related = SplitRelatedException e
ErrorFromAddingConstraint(x,e.Exception,m)|>ToPhased, related
| WrappedError (e,m) ->
let e,related = SplitRelatedException e
WrappedError(e.Exception,m)|>ToPhased, related
// Strip TargetInvocationException wrappers
| :? System.Reflection.TargetInvocationException as e ->
SplitRelatedException e.InnerException
| e ->
ToPhased(e), []
SplitRelatedException(err.Exception)
let DeclareMesssage = Microsoft.FSharp.Compiler.DiagnosticMessage.DeclareResourceString
do FSComp.SR.RunStartupValidation()
let SeeAlsoE() = DeclareResourceString("SeeAlso","%s")
let ConstraintSolverTupleDiffLengthsE() = DeclareResourceString("ConstraintSolverTupleDiffLengths","%d%d")
let ConstraintSolverInfiniteTypesE() = DeclareResourceString("ConstraintSolverInfiniteTypes", "%s%s")
let ConstraintSolverMissingConstraintE() = DeclareResourceString("ConstraintSolverMissingConstraint","%s")
let ConstraintSolverTypesNotInEqualityRelation1E() = DeclareResourceString("ConstraintSolverTypesNotInEqualityRelation1","%s%s")
let ConstraintSolverTypesNotInEqualityRelation2E() = DeclareResourceString("ConstraintSolverTypesNotInEqualityRelation2", "%s%s")
let ConstraintSolverTypesNotInSubsumptionRelationE() = DeclareResourceString("ConstraintSolverTypesNotInSubsumptionRelation","%s%s%s")
let ConstraintSolverErrorE() = DeclareResourceString("ConstraintSolverError","%s")
let ErrorFromAddingTypeEquation1E() = DeclareResourceString("ErrorFromAddingTypeEquation1","%s%s%s")
let ErrorFromAddingTypeEquation2E() = DeclareResourceString("ErrorFromAddingTypeEquation2","%s%s%s")
let ErrorFromApplyingDefault1E() = DeclareResourceString("ErrorFromApplyingDefault1","%s")
let ErrorFromApplyingDefault2E() = DeclareResourceString("ErrorFromApplyingDefault2","")
let ErrorsFromAddingSubsumptionConstraintE() = DeclareResourceString("ErrorsFromAddingSubsumptionConstraint","%s%s%s")
let UpperCaseIdentifierInPatternE() = DeclareResourceString("UpperCaseIdentifierInPattern","")
let NotUpperCaseConstructorE() = DeclareResourceString("NotUpperCaseConstructor","")
let PossibleOverloadE() = DeclareResourceString("PossibleOverload","%s%s")
let FunctionExpectedE() = DeclareResourceString("FunctionExpected","")
let BakedInMemberConstraintNameE() = DeclareResourceString("BakedInMemberConstraintName","%s")
let BadEventTransformationE() = DeclareResourceString("BadEventTransformation","")
let ParameterlessStructCtorE() = DeclareResourceString("ParameterlessStructCtor","")
let InterfaceNotRevealedE() = DeclareResourceString("InterfaceNotRevealed","%s")
let NotAFunction1E() = DeclareResourceString("NotAFunction1","")
let NotAFunction2E() = DeclareResourceString("NotAFunction2","")
let TyconBadArgsE() = DeclareResourceString("TyconBadArgs","%s%d%d")
let IndeterminateTypeE() = DeclareResourceString("IndeterminateType","")
let NameClash1E() = DeclareResourceString("NameClash1","%s%s")
let NameClash2E() = DeclareResourceString("NameClash2","%s%s%s%s%s")
let Duplicate1E() = DeclareResourceString("Duplicate1","%s")
let Duplicate2E() = DeclareResourceString("Duplicate2","%s%s")
let UndefinedName2E() = DeclareResourceString("UndefinedName2","")
let FieldNotMutableE() = DeclareResourceString("FieldNotMutable","")
let FieldsFromDifferentTypesE() = DeclareResourceString("FieldsFromDifferentTypes","%s%s")
let VarBoundTwiceE() = DeclareResourceString("VarBoundTwice","%s")
let RecursionE() = DeclareResourceString("Recursion","%s%s%s%s")
let InvalidRuntimeCoercionE() = DeclareResourceString("InvalidRuntimeCoercion","%s%s%s")
let IndeterminateRuntimeCoercionE() = DeclareResourceString("IndeterminateRuntimeCoercion","%s%s")
let IndeterminateStaticCoercionE() = DeclareResourceString("IndeterminateStaticCoercion","%s%s")
let StaticCoercionShouldUseBoxE() = DeclareResourceString("StaticCoercionShouldUseBox","%s%s")
let TypeIsImplicitlyAbstractE() = DeclareResourceString("TypeIsImplicitlyAbstract","")
let NonRigidTypar1E() = DeclareResourceString("NonRigidTypar1","%s%s")
let NonRigidTypar2E() = DeclareResourceString("NonRigidTypar2","%s%s")
let NonRigidTypar3E() = DeclareResourceString("NonRigidTypar3","%s%s")
let OBlockEndSentenceE() = DeclareResourceString("BlockEndSentence","")
let UnexpectedEndOfInputE() = DeclareResourceString("UnexpectedEndOfInput","")
let UnexpectedE() = DeclareResourceString("Unexpected","%s")
let NONTERM_interactionE() = DeclareResourceString("NONTERM.interaction","")
let NONTERM_hashDirectiveE() = DeclareResourceString("NONTERM.hashDirective","")
let NONTERM_fieldDeclE() = DeclareResourceString("NONTERM.fieldDecl","")
let NONTERM_unionCaseReprE() = DeclareResourceString("NONTERM.unionCaseRepr","")
let NONTERM_localBindingE() = DeclareResourceString("NONTERM.localBinding","")
let NONTERM_hardwhiteLetBindingsE() = DeclareResourceString("NONTERM.hardwhiteLetBindings","")
let NONTERM_classDefnMemberE() = DeclareResourceString("NONTERM.classDefnMember","")
let NONTERM_defnBindingsE() = DeclareResourceString("NONTERM.defnBindings","")
let NONTERM_classMemberSpfnE() = DeclareResourceString("NONTERM.classMemberSpfn","")
let NONTERM_valSpfnE() = DeclareResourceString("NONTERM.valSpfn","")
let NONTERM_tyconSpfnE() = DeclareResourceString("NONTERM.tyconSpfn","")
let NONTERM_anonLambdaExprE() = DeclareResourceString("NONTERM.anonLambdaExpr","")
let NONTERM_attrUnionCaseDeclE() = DeclareResourceString("NONTERM.attrUnionCaseDecl","")
let NONTERM_cPrototypeE() = DeclareResourceString("NONTERM.cPrototype","")
let NONTERM_objectImplementationMembersE() = DeclareResourceString("NONTERM.objectImplementationMembers","")
let NONTERM_ifExprCasesE() = DeclareResourceString("NONTERM.ifExprCases","")
let NONTERM_openDeclE() = DeclareResourceString("NONTERM.openDecl","")
let NONTERM_fileModuleSpecE() = DeclareResourceString("NONTERM.fileModuleSpec","")
let NONTERM_patternClausesE() = DeclareResourceString("NONTERM.patternClauses","")
let NONTERM_beginEndExprE() = DeclareResourceString("NONTERM.beginEndExpr","")
let NONTERM_recdExprE() = DeclareResourceString("NONTERM.recdExpr","")
let NONTERM_tyconDefnE() = DeclareResourceString("NONTERM.tyconDefn","")
let NONTERM_exconCoreE() = DeclareResourceString("NONTERM.exconCore","")
let NONTERM_typeNameInfoE() = DeclareResourceString("NONTERM.typeNameInfo","")
let NONTERM_attributeListE() = DeclareResourceString("NONTERM.attributeList","")
let NONTERM_quoteExprE() = DeclareResourceString("NONTERM.quoteExpr","")
let NONTERM_typeConstraintE() = DeclareResourceString("NONTERM.typeConstraint","")
let NONTERM_Category_ImplementationFileE() = DeclareResourceString("NONTERM.Category.ImplementationFile","")
let NONTERM_Category_DefinitionE() = DeclareResourceString("NONTERM.Category.Definition","")
let NONTERM_Category_SignatureFileE() = DeclareResourceString("NONTERM.Category.SignatureFile","")
let NONTERM_Category_PatternE() = DeclareResourceString("NONTERM.Category.Pattern","")
let NONTERM_Category_ExprE() = DeclareResourceString("NONTERM.Category.Expr","")
let NONTERM_Category_TypeE() = DeclareResourceString("NONTERM.Category.Type","")
let NONTERM_typeArgsActualE() = DeclareResourceString("NONTERM.typeArgsActual","")
let TokenName1E() = DeclareResourceString("TokenName1","%s")
let TokenName1TokenName2E() = DeclareResourceString("TokenName1TokenName2","%s%s")
let TokenName1TokenName2TokenName3E() = DeclareResourceString("TokenName1TokenName2TokenName3","%s%s%s")
let RuntimeCoercionSourceSealed1E() = DeclareResourceString("RuntimeCoercionSourceSealed1","%s")
let RuntimeCoercionSourceSealed2E() = DeclareResourceString("RuntimeCoercionSourceSealed2","%s")
let CoercionTargetSealedE() = DeclareResourceString("CoercionTargetSealed","%s")
let UpcastUnnecessaryE() = DeclareResourceString("UpcastUnnecessary","")
let TypeTestUnnecessaryE() = DeclareResourceString("TypeTestUnnecessary","")
let OverrideDoesntOverride1E() = DeclareResourceString("OverrideDoesntOverride1","%s")
let OverrideDoesntOverride2E() = DeclareResourceString("OverrideDoesntOverride2","%s")
let OverrideDoesntOverride3E() = DeclareResourceString("OverrideDoesntOverride3","%s")
let OverrideDoesntOverride4E() = DeclareResourceString("OverrideDoesntOverride4","%s")
let UnionCaseWrongArgumentsE() = DeclareResourceString("UnionCaseWrongArguments","%d%d")
let UnionPatternsBindDifferentNamesE() = DeclareResourceString("UnionPatternsBindDifferentNames","")
let RequiredButNotSpecifiedE() = DeclareResourceString("RequiredButNotSpecified","%s%s%s")
let UseOfAddressOfOperatorE() = DeclareResourceString("UseOfAddressOfOperator","")
let DefensiveCopyWarningE() = DeclareResourceString("DefensiveCopyWarning","%s")
let DeprecatedThreadStaticBindingWarningE() = DeclareResourceString("DeprecatedThreadStaticBindingWarning","")
let FunctionValueUnexpectedE() = DeclareResourceString("FunctionValueUnexpected","%s")
let UnitTypeExpectedE() = DeclareResourceString("UnitTypeExpected","")
let UnitTypeExpectedWithEqualityE() = DeclareResourceString("UnitTypeExpectedWithEquality","")
let UnitTypeExpectedWithPossiblePropertySetterE() = DeclareResourceString("UnitTypeExpectedWithPossiblePropertySetter","%s%s")
let UnitTypeExpectedWithPossibleAssignmentE() = DeclareResourceString("UnitTypeExpectedWithPossibleAssignment","%s")
let UnitTypeExpectedWithPossibleAssignmentToMutableE() = DeclareResourceString("UnitTypeExpectedWithPossibleAssignmentToMutable","%s")
let RecursiveUseCheckedAtRuntimeE() = DeclareResourceString("RecursiveUseCheckedAtRuntime","")
let LetRecUnsound1E() = DeclareResourceString("LetRecUnsound1","%s")
let LetRecUnsound2E() = DeclareResourceString("LetRecUnsound2","%s%s")
let LetRecUnsoundInnerE() = DeclareResourceString("LetRecUnsoundInner","%s")
let LetRecEvaluatedOutOfOrderE() = DeclareResourceString("LetRecEvaluatedOutOfOrder","")
let LetRecCheckedAtRuntimeE() = DeclareResourceString("LetRecCheckedAtRuntime","")
let SelfRefObjCtor1E() = DeclareResourceString("SelfRefObjCtor1","")
let SelfRefObjCtor2E() = DeclareResourceString("SelfRefObjCtor2","")
let VirtualAugmentationOnNullValuedTypeE() = DeclareResourceString("VirtualAugmentationOnNullValuedType","")
let NonVirtualAugmentationOnNullValuedTypeE() = DeclareResourceString("NonVirtualAugmentationOnNullValuedType","")
let NonUniqueInferredAbstractSlot1E() = DeclareResourceString("NonUniqueInferredAbstractSlot1","%s")
let NonUniqueInferredAbstractSlot2E() = DeclareResourceString("NonUniqueInferredAbstractSlot2","")
let NonUniqueInferredAbstractSlot3E() = DeclareResourceString("NonUniqueInferredAbstractSlot3","%s%s")
let NonUniqueInferredAbstractSlot4E() = DeclareResourceString("NonUniqueInferredAbstractSlot4","")
let Failure3E() = DeclareResourceString("Failure3","%s")
let Failure4E() = DeclareResourceString("Failure4","%s")
let FullAbstractionE() = DeclareResourceString("FullAbstraction","%s")
let MatchIncomplete1E() = DeclareResourceString("MatchIncomplete1","")
let MatchIncomplete2E() = DeclareResourceString("MatchIncomplete2","%s")
let MatchIncomplete3E() = DeclareResourceString("MatchIncomplete3","%s")
let MatchIncomplete4E() = DeclareResourceString("MatchIncomplete4","")
let RuleNeverMatchedE() = DeclareResourceString("RuleNeverMatched","")
let ValNotMutableE() = DeclareResourceString("ValNotMutable","%s")
let ValNotLocalE() = DeclareResourceString("ValNotLocal","")
let Obsolete1E() = DeclareResourceString("Obsolete1","")
let Obsolete2E() = DeclareResourceString("Obsolete2","%s")
let ExperimentalE() = DeclareResourceString("Experimental","%s")
let PossibleUnverifiableCodeE() = DeclareResourceString("PossibleUnverifiableCode","")
let DeprecatedE() = DeclareResourceString("Deprecated","%s")
let LibraryUseOnlyE() = DeclareResourceString("LibraryUseOnly","")
let MissingFieldsE() = DeclareResourceString("MissingFields","%s")
let ValueRestriction1E() = DeclareResourceString("ValueRestriction1","%s%s%s")
let ValueRestriction2E() = DeclareResourceString("ValueRestriction2","%s%s%s")
let ValueRestriction3E() = DeclareResourceString("ValueRestriction3","%s")
let ValueRestriction4E() = DeclareResourceString("ValueRestriction4","%s%s%s")
let ValueRestriction5E() = DeclareResourceString("ValueRestriction5","%s%s%s")
let RecoverableParseErrorE() = DeclareResourceString("RecoverableParseError","")
let ReservedKeywordE() = DeclareResourceString("ReservedKeyword","%s")
let IndentationProblemE() = DeclareResourceString("IndentationProblem","%s")
let OverrideInIntrinsicAugmentationE() = DeclareResourceString("OverrideInIntrinsicAugmentation","")
let OverrideInExtrinsicAugmentationE() = DeclareResourceString("OverrideInExtrinsicAugmentation","")
let IntfImplInIntrinsicAugmentationE() = DeclareResourceString("IntfImplInIntrinsicAugmentation","")
let IntfImplInExtrinsicAugmentationE() = DeclareResourceString("IntfImplInExtrinsicAugmentation","")
let UnresolvedReferenceNoRangeE() = DeclareResourceString("UnresolvedReferenceNoRange","%s")
let UnresolvedPathReferenceNoRangeE() = DeclareResourceString("UnresolvedPathReferenceNoRange","%s%s")
let HashIncludeNotAllowedInNonScriptE() = DeclareResourceString("HashIncludeNotAllowedInNonScript","")
let HashReferenceNotAllowedInNonScriptE() = DeclareResourceString("HashReferenceNotAllowedInNonScript","")
let HashDirectiveNotAllowedInNonScriptE() = DeclareResourceString("HashDirectiveNotAllowedInNonScript","")
let FileNameNotResolvedE() = DeclareResourceString("FileNameNotResolved","%s%s")
let AssemblyNotResolvedE() = DeclareResourceString("AssemblyNotResolved","%s")
let HashLoadedSourceHasIssues1E() = DeclareResourceString("HashLoadedSourceHasIssues1","")
let HashLoadedSourceHasIssues2E() = DeclareResourceString("HashLoadedSourceHasIssues2","")
let HashLoadedScriptConsideredSourceE() = DeclareResourceString("HashLoadedScriptConsideredSource","")
let InvalidInternalsVisibleToAssemblyName1E() = DeclareResourceString("InvalidInternalsVisibleToAssemblyName1","%s%s")
let InvalidInternalsVisibleToAssemblyName2E() = DeclareResourceString("InvalidInternalsVisibleToAssemblyName2","%s")
let LoadedSourceNotFoundIgnoringE() = DeclareResourceString("LoadedSourceNotFoundIgnoring","%s")
let MSBuildReferenceResolutionErrorE() = DeclareResourceString("MSBuildReferenceResolutionError","%s%s")
let TargetInvocationExceptionWrapperE() = DeclareResourceString("TargetInvocationExceptionWrapper","%s")
let getErrorString key = SR.GetString key
let (|InvalidArgument|_|) (exn:exn) = match exn with :? ArgumentException as e -> Some e.Message | _ -> None
let OutputPhasedErrorR errorStyle (os:StringBuilder) (err:PhasedDiagnostic) =
let rec OutputExceptionR (os:StringBuilder) error =
match error with
| ConstraintSolverTupleDiffLengths(_,tl1,tl2,m,m2) ->
os.Append(ConstraintSolverTupleDiffLengthsE().Format tl1.Length tl2.Length) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
| ConstraintSolverInfiniteTypes(contextInfo,denv,t1,t2,m,m2) ->
// REVIEW: consider if we need to show _cxs (the type parameter constraints)
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
os.Append(ConstraintSolverInfiniteTypesE().Format t1 t2) |> ignore
match contextInfo with
| ContextInfo.ReturnInComputationExpression ->
os.Append(" " + FSComp.SR.returnUsedInsteadOfReturnBang()) |> ignore
| ContextInfo.YieldInComputationExpression ->
os.Append(" " + FSComp.SR.yieldUsedInsteadOfYieldBang()) |> ignore
| _ -> ()
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
| ConstraintSolverMissingConstraint(denv,tpr,tpc,m,m2) ->
os.Append(ConstraintSolverMissingConstraintE().Format (NicePrint.stringOfTyparConstraint denv (tpr,tpc))) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
| ConstraintSolverTypesNotInEqualityRelation(denv,(TType_measure _ as t1),(TType_measure _ as t2),m,m2,contextInfo) ->
// REVIEW: consider if we need to show _cxs (the type parameter constraints)
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
match contextInfo with
| ContextInfo.OmittedElseBranch range when range = m -> os.Append(FSComp.SR.missingElseBranch(t2)) |> ignore
| ContextInfo.ElseBranchResult range when range = m -> os.Append(FSComp.SR.elseBranchHasWrongType(t1,t2)) |> ignore
| _ -> os.Append(ConstraintSolverTypesNotInEqualityRelation1E().Format t1 t2 ) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
| ConstraintSolverTypesNotInEqualityRelation(denv,t1,t2,m,m2,contextInfo) ->
// REVIEW: consider if we need to show _cxs (the type parameter constraints)
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
match contextInfo with
| ContextInfo.OmittedElseBranch range when range = m -> os.Append(FSComp.SR.missingElseBranch(t2)) |> ignore
| ContextInfo.ElseBranchResult range when range = m -> os.Append(FSComp.SR.elseBranchHasWrongType(t1,t2)) |> ignore
| _ -> os.Append(ConstraintSolverTypesNotInEqualityRelation2E().Format t1 t2) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m)) |> ignore
| ConstraintSolverTypesNotInSubsumptionRelation(denv,t1,t2,m,m2) ->
// REVIEW: consider if we need to show _cxs (the type parameter constraints)
let t1, t2, cxs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
os.Append(ConstraintSolverTypesNotInSubsumptionRelationE().Format t2 t1 cxs) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m2)) |> ignore
| ConstraintSolverError(msg,m,m2) ->
os.Append(ConstraintSolverErrorE().Format msg) |> ignore
if m.StartLine <> m2.StartLine then
os.Append(SeeAlsoE().Format (stringOfRange m2)) |> ignore
| ConstraintSolverRelatedInformation(fopt,_,e) ->
match e with
| ConstraintSolverError _ -> OutputExceptionR os e
| _ -> ()
fopt |> Option.iter (Printf.bprintf os " %s")
| ErrorFromAddingTypeEquation(g,denv,t1,t2,ConstraintSolverTypesNotInEqualityRelation(_, t1', t2',m ,_ , contextInfo),_)
when typeEquiv g t1 t1'
&& typeEquiv g t2 t2' ->
let t1,t2,tpcs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
match contextInfo with
| ContextInfo.OmittedElseBranch range when range = m -> os.Append(FSComp.SR.missingElseBranch(t2)) |> ignore
| ContextInfo.ElseBranchResult range when range = m -> os.Append(FSComp.SR.elseBranchHasWrongType(t1,t2)) |> ignore
| ContextInfo.TupleInRecordFields ->
os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs) |> ignore
os.Append(System.Environment.NewLine + FSComp.SR.commaInsteadOfSemicolonInRecord()) |> ignore
| _ when t2 = "bool" && t1.EndsWith " ref" ->
os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs) |> ignore
os.Append(System.Environment.NewLine + FSComp.SR.derefInsteadOfNot()) |> ignore
| _ -> os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs) |> ignore
| ErrorFromAddingTypeEquation(_,_,_,_,((ConstraintSolverTypesNotInEqualityRelation (_,_,_,_,_,contextInfo) ) as e), _) when contextInfo <> ContextInfo.NoContext ->
OutputExceptionR os e
| ErrorFromAddingTypeEquation(_,_,_,_,((ConstraintSolverTypesNotInSubsumptionRelation _ | ConstraintSolverError _ ) as e), _) ->
OutputExceptionR os e
| ErrorFromAddingTypeEquation(g,denv,t1,t2,e,_) ->
if not (typeEquiv g t1 t2) then
let t1,t2,tpcs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
if t1<>t2 + tpcs then os.Append(ErrorFromAddingTypeEquation2E().Format t1 t2 tpcs) |> ignore
OutputExceptionR os e
| ErrorFromApplyingDefault(_,denv,_,defaultType,e,_) ->
let defaultType = NicePrint.minimalStringOfType denv defaultType
os.Append(ErrorFromApplyingDefault1E().Format defaultType) |> ignore
OutputExceptionR os e
os.Append(ErrorFromApplyingDefault2E().Format) |> ignore
| ErrorsFromAddingSubsumptionConstraint(g,denv,t1,t2,e,contextInfo,_) ->
match contextInfo with
| ContextInfo.DowncastUsedInsteadOfUpcast isOperator ->
let t1,t2,_ = NicePrint.minimalStringsOfTwoTypes denv t1 t2
if isOperator then
os.Append(FSComp.SR.considerUpcastOperator(t1,t2) |> snd) |> ignore
else
os.Append(FSComp.SR.considerUpcast(t1,t2) |> snd) |> ignore
| _ ->
if not (typeEquiv g t1 t2) then
let t1,t2,tpcs = NicePrint.minimalStringsOfTwoTypes denv t1 t2
if t1 <> (t2 + tpcs) then
os.Append(ErrorsFromAddingSubsumptionConstraintE().Format t2 t1 tpcs) |> ignore
else
OutputExceptionR os e
else
OutputExceptionR os e
| UpperCaseIdentifierInPattern(_) ->
os.Append(UpperCaseIdentifierInPatternE().Format) |> ignore
| NotUpperCaseConstructor(_) ->
os.Append(NotUpperCaseConstructorE().Format) |> ignore
| ErrorFromAddingConstraint(_,e,_) ->
OutputExceptionR os e
#if EXTENSIONTYPING
| ExtensionTyping.ProvidedTypeResolutionNoRange(e)
| ExtensionTyping.ProvidedTypeResolution(_,e) ->
OutputExceptionR os e
| :? TypeProviderError as e ->
os.Append(e.ContextualErrorMessage) |> ignore
#endif
| UnresolvedOverloading(_,_,mtext,_) ->
os.Append(mtext) |> ignore
| UnresolvedConversionOperator(denv,fromTy,toTy,_) ->
let t1,t2,_tpcs = NicePrint.minimalStringsOfTwoTypes denv fromTy toTy
os.Append(FSComp.SR.csTypeDoesNotSupportConversion(t1,t2)) |> ignore
| PossibleOverload(_,minfo, originalError, _) ->
// print original error that describes reason why this overload was rejected
let buf = new StringBuilder()
OutputExceptionR buf originalError
os.Append(PossibleOverloadE().Format minfo (buf.ToString())) |> ignore
//| PossibleBestOverload(_,minfo,m) ->
// Printf.bprintf os "\n\nPossible best overload: '%s'." minfo
| FunctionExpected _ ->
os.Append(FunctionExpectedE().Format) |> ignore
| BakedInMemberConstraintName(nm,_) ->
os.Append(BakedInMemberConstraintNameE().Format nm) |> ignore
| StandardOperatorRedefinitionWarning(msg,_) ->
os.Append(msg) |> ignore
| BadEventTransformation(_) ->
os.Append(BadEventTransformationE().Format) |> ignore
| ParameterlessStructCtor(_) ->
os.Append(ParameterlessStructCtorE().Format) |> ignore
| InterfaceNotRevealed(denv,ity,_) ->
os.Append(InterfaceNotRevealedE().Format (NicePrint.minimalStringOfType denv ity)) |> ignore
| NotAFunction(_,_,_,marg) ->
if marg.StartColumn = 0 then
os.Append(NotAFunction1E().Format) |> ignore
else
os.Append(NotAFunction2E().Format) |> ignore
| TyconBadArgs(_,tcref,d,_) ->
let exp = tcref.TyparsNoRange.Length
if exp = 0 then
os.Append(FSComp.SR.buildUnexpectedTypeArgs(fullDisplayTextOfTyconRef tcref, d)) |> ignore
else
os.Append(TyconBadArgsE().Format (fullDisplayTextOfTyconRef tcref) exp d) |> ignore
| IndeterminateType(_) ->
os.Append(IndeterminateTypeE().Format) |> ignore
| NameClash(nm,k1,nm1,_,k2,nm2,_) ->
if nm = nm1 && nm1 = nm2 && k1 = k2 then
os.Append(NameClash1E().Format k1 nm1) |> ignore
else
os.Append(NameClash2E().Format k1 nm1 nm k2 nm2) |> ignore
| Duplicate(k,s,_) ->
if k = "member" then
os.Append(Duplicate1E().Format (DecompileOpName s)) |> ignore
else
os.Append(Duplicate2E().Format k (DecompileOpName s)) |> ignore
| UndefinedName(_,k,id,suggestionsF) ->
os.Append(k (DecompileOpName id.idText)) |> ignore
let filtered = ErrorResolutionHints.FilterPredictions id.idText suggestionsF
if List.isEmpty filtered |> not then
os.Append(ErrorResolutionHints.FormatPredictions errorStyle DecompileOpName filtered) |> ignore
| InternalUndefinedItemRef(f,smr,ccuName,s) ->
let _, errs = f(smr, ccuName, s)
os.Append(errs) |> ignore
| FieldNotMutable _ ->
os.Append(FieldNotMutableE().Format) |> ignore
| FieldsFromDifferentTypes (_,fref1,fref2,_) ->
os.Append(FieldsFromDifferentTypesE().Format fref1.FieldName fref2.FieldName) |> ignore
| VarBoundTwice(id) ->
os.Append(VarBoundTwiceE().Format (DecompileOpName id.idText)) |> ignore
| Recursion (denv,id,ty1,ty2,_) ->
let t1,t2,tpcs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
os.Append(RecursionE().Format (DecompileOpName id.idText) t1 t2 tpcs) |> ignore
| InvalidRuntimeCoercion(denv,ty1,ty2,_) ->
let t1,t2,tpcs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
os.Append(InvalidRuntimeCoercionE().Format t1 t2 tpcs) |> ignore
| IndeterminateRuntimeCoercion(denv,ty1,ty2,_) ->
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
os.Append(IndeterminateRuntimeCoercionE().Format t1 t2) |> ignore
| IndeterminateStaticCoercion(denv,ty1,ty2,_) ->
// REVIEW: consider if we need to show _cxs (the type parameter constrants)
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
os.Append(IndeterminateStaticCoercionE().Format t1 t2) |> ignore
| StaticCoercionShouldUseBox(denv,ty1,ty2,_) ->
// REVIEW: consider if we need to show _cxs (the type parameter constrants)
let t1, t2, _cxs = NicePrint.minimalStringsOfTwoTypes denv ty1 ty2
os.Append(StaticCoercionShouldUseBoxE().Format t1 t2) |> ignore
| TypeIsImplicitlyAbstract(_) ->
os.Append(TypeIsImplicitlyAbstractE().Format) |> ignore
| NonRigidTypar(denv,tpnmOpt,typarRange,ty1,ty,_) ->
// REVIEW: consider if we need to show _cxs (the type parameter constrants)
let _, (ty1,ty), _cxs = PrettyTypes.PrettifyTypes2 denv.g (ty1,ty)
match tpnmOpt with
| None ->
os.Append(NonRigidTypar1E().Format (stringOfRange typarRange) (NicePrint.stringOfTy denv ty)) |> ignore
| Some tpnm ->
match ty1 with
| TType_measure _ ->
os.Append(NonRigidTypar2E().Format tpnm (NicePrint.stringOfTy denv ty)) |> ignore
| _ ->
os.Append(NonRigidTypar3E().Format tpnm (NicePrint.stringOfTy denv ty)) |> ignore
| SyntaxError (ctxt,_) ->
let ctxt = unbox<Parsing.ParseErrorContext<Parser.token>>(ctxt)
let (|EndOfStructuredConstructToken|_|) token =
match token with
| Parser.TOKEN_ODECLEND
| Parser.TOKEN_OBLOCKSEP
| Parser.TOKEN_OEND
| Parser.TOKEN_ORIGHT_BLOCK_END
| Parser.TOKEN_OBLOCKEND | Parser.TOKEN_OBLOCKEND_COMING_SOON | Parser.TOKEN_OBLOCKEND_IS_HERE -> Some()
| _ -> None
let tokenIdToText tid =
match tid with
| Parser.TOKEN_IDENT -> getErrorString("Parser.TOKEN.IDENT")
| Parser.TOKEN_BIGNUM
| Parser.TOKEN_INT8
| Parser.TOKEN_UINT8
| Parser.TOKEN_INT16
| Parser.TOKEN_UINT16
| Parser.TOKEN_INT32
| Parser.TOKEN_UINT32
| Parser.TOKEN_INT64
| Parser.TOKEN_UINT64
| Parser.TOKEN_UNATIVEINT
| Parser.TOKEN_NATIVEINT -> getErrorString("Parser.TOKEN.INT")
| Parser.TOKEN_IEEE32
| Parser.TOKEN_IEEE64 -> getErrorString("Parser.TOKEN.FLOAT")
| Parser.TOKEN_DECIMAL -> getErrorString("Parser.TOKEN.DECIMAL")
| Parser.TOKEN_CHAR -> getErrorString("Parser.TOKEN.CHAR")
| Parser.TOKEN_BASE -> getErrorString("Parser.TOKEN.BASE")
| Parser.TOKEN_LPAREN_STAR_RPAREN -> getErrorString("Parser.TOKEN.LPAREN.STAR.RPAREN")
| Parser.TOKEN_DOLLAR -> getErrorString("Parser.TOKEN.DOLLAR")
| Parser.TOKEN_INFIX_STAR_STAR_OP -> getErrorString("Parser.TOKEN.INFIX.STAR.STAR.OP")
| Parser.TOKEN_INFIX_COMPARE_OP -> getErrorString("Parser.TOKEN.INFIX.COMPARE.OP")
| Parser.TOKEN_COLON_GREATER -> getErrorString("Parser.TOKEN.COLON.GREATER")
| Parser.TOKEN_COLON_COLON ->getErrorString("Parser.TOKEN.COLON.COLON")
| Parser.TOKEN_PERCENT_OP -> getErrorString("Parser.TOKEN.PERCENT.OP")
| Parser.TOKEN_INFIX_AT_HAT_OP -> getErrorString("Parser.TOKEN.INFIX.AT.HAT.OP")
| Parser.TOKEN_INFIX_BAR_OP -> getErrorString("Parser.TOKEN.INFIX.BAR.OP")
| Parser.TOKEN_PLUS_MINUS_OP -> getErrorString("Parser.TOKEN.PLUS.MINUS.OP")
| Parser.TOKEN_PREFIX_OP -> getErrorString("Parser.TOKEN.PREFIX.OP")
| Parser.TOKEN_COLON_QMARK_GREATER -> getErrorString("Parser.TOKEN.COLON.QMARK.GREATER")
| Parser.TOKEN_INFIX_STAR_DIV_MOD_OP -> getErrorString("Parser.TOKEN.INFIX.STAR.DIV.MOD.OP")
| Parser.TOKEN_INFIX_AMP_OP -> getErrorString("Parser.TOKEN.INFIX.AMP.OP")
| Parser.TOKEN_AMP -> getErrorString("Parser.TOKEN.AMP")
| Parser.TOKEN_AMP_AMP -> getErrorString("Parser.TOKEN.AMP.AMP")
| Parser.TOKEN_BAR_BAR -> getErrorString("Parser.TOKEN.BAR.BAR")
| Parser.TOKEN_LESS -> getErrorString("Parser.TOKEN.LESS")
| Parser.TOKEN_GREATER -> getErrorString("Parser.TOKEN.GREATER")
| Parser.TOKEN_QMARK -> getErrorString("Parser.TOKEN.QMARK")
| Parser.TOKEN_QMARK_QMARK -> getErrorString("Parser.TOKEN.QMARK.QMARK")
| Parser.TOKEN_COLON_QMARK-> getErrorString("Parser.TOKEN.COLON.QMARK")
| Parser.TOKEN_INT32_DOT_DOT -> getErrorString("Parser.TOKEN.INT32.DOT.DOT")
| Parser.TOKEN_DOT_DOT -> getErrorString("Parser.TOKEN.DOT.DOT")
| Parser.TOKEN_QUOTE -> getErrorString("Parser.TOKEN.QUOTE")
| Parser.TOKEN_STAR -> getErrorString("Parser.TOKEN.STAR")
| Parser.TOKEN_HIGH_PRECEDENCE_TYAPP -> getErrorString("Parser.TOKEN.HIGH.PRECEDENCE.TYAPP")
| Parser.TOKEN_COLON -> getErrorString("Parser.TOKEN.COLON")
| Parser.TOKEN_COLON_EQUALS -> getErrorString("Parser.TOKEN.COLON.EQUALS")
| Parser.TOKEN_LARROW -> getErrorString("Parser.TOKEN.LARROW")
| Parser.TOKEN_EQUALS -> getErrorString("Parser.TOKEN.EQUALS")
| Parser.TOKEN_GREATER_BAR_RBRACK -> getErrorString("Parser.TOKEN.GREATER.BAR.RBRACK")
| Parser.TOKEN_MINUS -> getErrorString("Parser.TOKEN.MINUS")
| Parser.TOKEN_ADJACENT_PREFIX_OP -> getErrorString("Parser.TOKEN.ADJACENT.PREFIX.OP")
| Parser.TOKEN_FUNKY_OPERATOR_NAME -> getErrorString("Parser.TOKEN.FUNKY.OPERATOR.NAME")
| Parser.TOKEN_COMMA-> getErrorString("Parser.TOKEN.COMMA")
| Parser.TOKEN_DOT -> getErrorString("Parser.TOKEN.DOT")
| Parser.TOKEN_BAR-> getErrorString("Parser.TOKEN.BAR")
| Parser.TOKEN_HASH -> getErrorString("Parser.TOKEN.HASH")
| Parser.TOKEN_UNDERSCORE -> getErrorString("Parser.TOKEN.UNDERSCORE")
| Parser.TOKEN_SEMICOLON -> getErrorString("Parser.TOKEN.SEMICOLON")
| Parser.TOKEN_SEMICOLON_SEMICOLON-> getErrorString("Parser.TOKEN.SEMICOLON.SEMICOLON")
| Parser.TOKEN_LPAREN-> getErrorString("Parser.TOKEN.LPAREN")
| Parser.TOKEN_RPAREN | Parser.TOKEN_RPAREN_COMING_SOON | Parser.TOKEN_RPAREN_IS_HERE -> getErrorString("Parser.TOKEN.RPAREN")
| Parser.TOKEN_LQUOTE -> getErrorString("Parser.TOKEN.LQUOTE")
| Parser.TOKEN_LBRACK -> getErrorString("Parser.TOKEN.LBRACK")
| Parser.TOKEN_LBRACK_BAR -> getErrorString("Parser.TOKEN.LBRACK.BAR")
| Parser.TOKEN_LBRACK_LESS -> getErrorString("Parser.TOKEN.LBRACK.LESS")
| Parser.TOKEN_LBRACE -> getErrorString("Parser.TOKEN.LBRACE")
| Parser.TOKEN_LBRACE_LESS-> getErrorString("Parser.TOKEN.LBRACE.LESS")
| Parser.TOKEN_BAR_RBRACK -> getErrorString("Parser.TOKEN.BAR.RBRACK")
| Parser.TOKEN_GREATER_RBRACE -> getErrorString("Parser.TOKEN.GREATER.RBRACE")
| Parser.TOKEN_GREATER_RBRACK -> getErrorString("Parser.TOKEN.GREATER.RBRACK")
| Parser.TOKEN_RQUOTE_DOT _
| Parser.TOKEN_RQUOTE -> getErrorString("Parser.TOKEN.RQUOTE")
| Parser.TOKEN_RBRACK -> getErrorString("Parser.TOKEN.RBRACK")
| Parser.TOKEN_RBRACE | Parser.TOKEN_RBRACE_COMING_SOON | Parser.TOKEN_RBRACE_IS_HERE -> getErrorString("Parser.TOKEN.RBRACE")
| Parser.TOKEN_PUBLIC -> getErrorString("Parser.TOKEN.PUBLIC")
| Parser.TOKEN_PRIVATE -> getErrorString("Parser.TOKEN.PRIVATE")
| Parser.TOKEN_INTERNAL -> getErrorString("Parser.TOKEN.INTERNAL")
| Parser.TOKEN_CONSTRAINT -> getErrorString("Parser.TOKEN.CONSTRAINT")
| Parser.TOKEN_INSTANCE -> getErrorString("Parser.TOKEN.INSTANCE")
| Parser.TOKEN_DELEGATE -> getErrorString("Parser.TOKEN.DELEGATE")
| Parser.TOKEN_INHERIT -> getErrorString("Parser.TOKEN.INHERIT")
| Parser.TOKEN_CONSTRUCTOR-> getErrorString("Parser.TOKEN.CONSTRUCTOR")
| Parser.TOKEN_DEFAULT -> getErrorString("Parser.TOKEN.DEFAULT")
| Parser.TOKEN_OVERRIDE-> getErrorString("Parser.TOKEN.OVERRIDE")
| Parser.TOKEN_ABSTRACT-> getErrorString("Parser.TOKEN.ABSTRACT")
| Parser.TOKEN_CLASS-> getErrorString("Parser.TOKEN.CLASS")
| Parser.TOKEN_MEMBER -> getErrorString("Parser.TOKEN.MEMBER")
| Parser.TOKEN_STATIC -> getErrorString("Parser.TOKEN.STATIC")
| Parser.TOKEN_NAMESPACE-> getErrorString("Parser.TOKEN.NAMESPACE")
| Parser.TOKEN_OBLOCKBEGIN -> getErrorString("Parser.TOKEN.OBLOCKBEGIN")
| EndOfStructuredConstructToken -> getErrorString("Parser.TOKEN.OBLOCKEND")
| Parser.TOKEN_THEN
| Parser.TOKEN_OTHEN -> getErrorString("Parser.TOKEN.OTHEN")
| Parser.TOKEN_ELSE
| Parser.TOKEN_OELSE -> getErrorString("Parser.TOKEN.OELSE")
| Parser.TOKEN_LET(_)
| Parser.TOKEN_OLET(_) -> getErrorString("Parser.TOKEN.OLET")
| Parser.TOKEN_OBINDER
| Parser.TOKEN_BINDER -> getErrorString("Parser.TOKEN.BINDER")
| Parser.TOKEN_ODO -> getErrorString("Parser.TOKEN.ODO")
| Parser.TOKEN_OWITH -> getErrorString("Parser.TOKEN.OWITH")
| Parser.TOKEN_OFUNCTION -> getErrorString("Parser.TOKEN.OFUNCTION")
| Parser.TOKEN_OFUN -> getErrorString("Parser.TOKEN.OFUN")
| Parser.TOKEN_ORESET -> getErrorString("Parser.TOKEN.ORESET")
| Parser.TOKEN_ODUMMY -> getErrorString("Parser.TOKEN.ODUMMY")
| Parser.TOKEN_DO_BANG
| Parser.TOKEN_ODO_BANG -> getErrorString("Parser.TOKEN.ODO.BANG")
| Parser.TOKEN_YIELD -> getErrorString("Parser.TOKEN.YIELD")
| Parser.TOKEN_YIELD_BANG -> getErrorString("Parser.TOKEN.YIELD.BANG")
| Parser.TOKEN_OINTERFACE_MEMBER-> getErrorString("Parser.TOKEN.OINTERFACE.MEMBER")
| Parser.TOKEN_ELIF -> getErrorString("Parser.TOKEN.ELIF")
| Parser.TOKEN_RARROW -> getErrorString("Parser.TOKEN.RARROW")
| Parser.TOKEN_SIG -> getErrorString("Parser.TOKEN.SIG")
| Parser.TOKEN_STRUCT -> getErrorString("Parser.TOKEN.STRUCT")
| Parser.TOKEN_UPCAST -> getErrorString("Parser.TOKEN.UPCAST")
| Parser.TOKEN_DOWNCAST -> getErrorString("Parser.TOKEN.DOWNCAST")
| Parser.TOKEN_NULL -> getErrorString("Parser.TOKEN.NULL")
| Parser.TOKEN_RESERVED -> getErrorString("Parser.TOKEN.RESERVED")
| Parser.TOKEN_MODULE | Parser.TOKEN_MODULE_COMING_SOON | Parser.TOKEN_MODULE_IS_HERE -> getErrorString("Parser.TOKEN.MODULE")
| Parser.TOKEN_AND -> getErrorString("Parser.TOKEN.AND")
| Parser.TOKEN_AS -> getErrorString("Parser.TOKEN.AS")
| Parser.TOKEN_ASSERT -> getErrorString("Parser.TOKEN.ASSERT")
| Parser.TOKEN_OASSERT -> getErrorString("Parser.TOKEN.ASSERT")
| Parser.TOKEN_ASR-> getErrorString("Parser.TOKEN.ASR")
| Parser.TOKEN_DOWNTO -> getErrorString("Parser.TOKEN.DOWNTO")
| Parser.TOKEN_EXCEPTION -> getErrorString("Parser.TOKEN.EXCEPTION")
| Parser.TOKEN_FALSE -> getErrorString("Parser.TOKEN.FALSE")
| Parser.TOKEN_FOR -> getErrorString("Parser.TOKEN.FOR")
| Parser.TOKEN_FUN -> getErrorString("Parser.TOKEN.FUN")
| Parser.TOKEN_FUNCTION-> getErrorString("Parser.TOKEN.FUNCTION")
| Parser.TOKEN_FINALLY -> getErrorString("Parser.TOKEN.FINALLY")
| Parser.TOKEN_LAZY -> getErrorString("Parser.TOKEN.LAZY")
| Parser.TOKEN_OLAZY -> getErrorString("Parser.TOKEN.LAZY")
| Parser.TOKEN_MATCH -> getErrorString("Parser.TOKEN.MATCH")
| Parser.TOKEN_MUTABLE -> getErrorString("Parser.TOKEN.MUTABLE")
| Parser.TOKEN_NEW -> getErrorString("Parser.TOKEN.NEW")
| Parser.TOKEN_OF -> getErrorString("Parser.TOKEN.OF")
| Parser.TOKEN_OPEN -> getErrorString("Parser.TOKEN.OPEN")
| Parser.TOKEN_OR -> getErrorString("Parser.TOKEN.OR")
| Parser.TOKEN_VOID -> getErrorString("Parser.TOKEN.VOID")
| Parser.TOKEN_EXTERN-> getErrorString("Parser.TOKEN.EXTERN")
| Parser.TOKEN_INTERFACE -> getErrorString("Parser.TOKEN.INTERFACE")
| Parser.TOKEN_REC -> getErrorString("Parser.TOKEN.REC")
| Parser.TOKEN_TO -> getErrorString("Parser.TOKEN.TO")
| Parser.TOKEN_TRUE -> getErrorString("Parser.TOKEN.TRUE")
| Parser.TOKEN_TRY -> getErrorString("Parser.TOKEN.TRY")
| Parser.TOKEN_TYPE | Parser.TOKEN_TYPE_COMING_SOON | Parser.TOKEN_TYPE_IS_HERE -> getErrorString("Parser.TOKEN.TYPE")
| Parser.TOKEN_VAL -> getErrorString("Parser.TOKEN.VAL")
| Parser.TOKEN_INLINE -> getErrorString("Parser.TOKEN.INLINE")
| Parser.TOKEN_WHEN -> getErrorString("Parser.TOKEN.WHEN")
| Parser.TOKEN_WHILE -> getErrorString("Parser.TOKEN.WHILE")
| Parser.TOKEN_WITH-> getErrorString("Parser.TOKEN.WITH")
| Parser.TOKEN_IF -> getErrorString("Parser.TOKEN.IF")
| Parser.TOKEN_DO -> getErrorString("Parser.TOKEN.DO")
| Parser.TOKEN_GLOBAL -> getErrorString("Parser.TOKEN.GLOBAL")
| Parser.TOKEN_DONE -> getErrorString("Parser.TOKEN.DONE")
| Parser.TOKEN_IN | Parser.TOKEN_JOIN_IN -> getErrorString("Parser.TOKEN.IN")
| Parser.TOKEN_HIGH_PRECEDENCE_PAREN_APP-> getErrorString("Parser.TOKEN.HIGH.PRECEDENCE.PAREN.APP")
| Parser.TOKEN_HIGH_PRECEDENCE_BRACK_APP-> getErrorString("Parser.TOKEN.HIGH.PRECEDENCE.BRACK.APP")