Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error reporting for let bindings. #17601

Merged
merged 44 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
523ccd9
Use `SynPat` range for let binding errors
edgarfgp Aug 24, 2024
619b4f6
update error range for tcAttributesAreNotPermittedOnLetBindings
edgarfgp Aug 24, 2024
912ab6d
Include typars
edgarfgp Aug 24, 2024
4e4f496
AP better error message
edgarfgp Aug 25, 2024
db78b2e
fantomas
edgarfgp Aug 25, 2024
730e980
Fix tests
edgarfgp Aug 25, 2024
4b7967e
fantomas
edgarfgp Aug 25, 2024
49c59fb
update tests
edgarfgp Aug 25, 2024
2ac08a7
Add a new compiler error for multi-case partial active patterns are n…
edgarfgp Aug 26, 2024
82254f4
use tcPartialActivePattern and add more tests
edgarfgp Aug 26, 2024
14b9b61
update tests
edgarfgp Aug 26, 2024
44c170b
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 26, 2024
3e6eb43
Update src/Compiler/FSComp.txt
edgarfgp Aug 26, 2024
e65f1c4
Update FSComp.txt
edgarfgp Aug 26, 2024
5ed584e
Update src/Compiler/FSComp.txt
edgarfgp Aug 26, 2024
998bf6b
Merge branch 'better-let-binding-error-range' of github.com:edgarfgp/…
edgarfgp Aug 26, 2024
4c9cbc0
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 26, 2024
924e17e
Merge branch 'better-let-binding-error-range' of github.com:edgarfgp/…
edgarfgp Aug 26, 2024
5518da5
more tests
edgarfgp Aug 26, 2024
9d887b6
release notes
edgarfgp Aug 26, 2024
a041fb7
Update xlf
edgarfgp Aug 26, 2024
714770f
reduce diff
edgarfgp Aug 26, 2024
1a7819b
update tests
edgarfgp Aug 27, 2024
d6a5137
baselines
edgarfgp Aug 27, 2024
0b544fb
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 27, 2024
fda8c6f
move `neg16.bsl` content to different tests
edgarfgp Aug 28, 2024
ae72626
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 28, 2024
8d94763
move `neg16.bsl` content to different tests
edgarfgp Aug 28, 2024
d7877ec
Merge branch 'better-let-binding-error-range' of github.com:edgarfgp/…
edgarfgp Aug 28, 2024
9decd9c
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 28, 2024
db40ac6
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 29, 2024
36d81d8
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 29, 2024
0e86a93
Update bsl
psfinaki Aug 30, 2024
2a10d3f
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 30, 2024
a79ce39
Update last failing tests.
edgarfgp Aug 30, 2024
b2a8f0b
Update last failing tests.
edgarfgp Aug 30, 2024
4e1ec09
Merge branch 'main' into better-let-binding-error-range
edgarfgp Aug 30, 2024
3cb5d6f
FactForDESKTOP neg16
edgarfgp Sep 2, 2024
cf4f57b
Merge branch 'better-let-binding-error-range' of github.com:edgarfgp/…
edgarfgp Sep 2, 2024
bd5c333
Merge branch 'main' into better-let-binding-error-range
edgarfgp Sep 3, 2024
843b522
fix bsl
psfinaki Sep 3, 2024
b266304
Merge branch 'main' into better-let-binding-error-range
edgarfgp Sep 3, 2024
f299048
Merge branch 'main' into better-let-binding-error-range
psfinaki Sep 3, 2024
0638148
Merge branch 'main' into better-let-binding-error-range
edgarfgp Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* Applied nullable reference types to FSharp.Compiler.Service itself ([PR #15310](https://github.com/dotnet/fsharp/pull/15310))
* Ensure that isinteractive multi-emit backing fields are not public. ([Issue #17439](https://github.com/dotnet/fsharp/issues/17438)), ([PR #17439](https://github.com/dotnet/fsharp/pull/17439))
* Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521))
* Better error reporting for let bindings. ([PR #17601](https://github.com/dotnet/fsharp/pull/17601))
* Optimize ILTypeDef interface impls reading from metadata. ([PR #17382](https://github.com/dotnet/fsharp/pull/17382))


### Breaking Changes
28 changes: 21 additions & 7 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ module GeneralizationHelpers =
// to C<_> occurs then generate C<?ty> for a fresh type inference variable ?ty.
//-------------------------------------------------------------------------

let CheckDeclaredTyparsPermitted (memFlagsOpt: SynMemberFlags option, declaredTypars, m) =
let CheckDeclaredTyparsPermitted (memFlagsOpt: SynMemberFlags option, declaredTypars: Typars, m) =
match memFlagsOpt with
| None -> ()
| Some memberFlags ->
Expand All @@ -2284,7 +2284,13 @@ module GeneralizationHelpers =
| SynMemberKind.PropertySet
| SynMemberKind.PropertyGetSet ->
if not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcPropertyRequiresExplicitTypeParameters(), m))
let declaredTyparsRange =
declaredTypars
|> List.map(fun typar -> typar.Range)

let m = declaredTyparsRange |> List.fold (fun r a -> unionRanges r a) range.Zero

errorR(Error(FSComp.SR.tcPropertyRequiresExplicitTypeParameters(), m))
| SynMemberKind.Constructor ->
if not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcConstructorCannotHaveTypeParameters(), m))
Expand Down Expand Up @@ -10816,8 +10822,9 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
let envinner = AddDeclaredTypars NoCheckForDuplicateTypars (enclosingDeclaredTypars@declaredTypars) env

match bind with
| NormalizedBinding(vis, kind, isInline, isMutable, attrs, xmlDoc, _, valSynData, pat, NormalizedBindingRhs(spatsL, rtyOpt, rhsExpr), mBinding, debugPoint) ->
| NormalizedBinding(vis, kind, isInline, isMutable, attrs, xmlDoc, _, valSynData, pat, NormalizedBindingRhs(spatsL, rtyOpt, rhsExpr), _, debugPoint) ->
let (SynValData(memberFlags = memberFlagsOpt)) = valSynData
let mBinding = pat.Range
edgarfgp marked this conversation as resolved.
Show resolved Hide resolved

let isClassLetBinding =
match declKind, kind with
Expand Down Expand Up @@ -10863,8 +10870,10 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
// targeting the return value.
let tgtEx = if isRet then enum 0 else AttributeTargets.ReturnValue
let attrs, _ = TcAttributesMaybeFailEx false cenv envinner tgt tgtEx attrs
let attrs: Attrib list = attrs
if attrTgt = enum 0 && not (isNil attrs) then
errorR(Error(FSComp.SR.tcAttributesAreNotPermittedOnLetBindings(), mBinding))
for attr in attrs do
edgarfgp marked this conversation as resolved.
Show resolved Hide resolved
errorR(Error(FSComp.SR.tcAttributesAreNotPermittedOnLetBindings(), attr.Range))
attrs

// Rotate [<return:...>] from binding to return value
Expand Down Expand Up @@ -10984,8 +10993,12 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
let envinner =
match apinfoOpt with
| Some (apinfo, apOverallTy, m) ->
if Option.isSome memberFlagsOpt || (not apinfo.IsTotal && apinfo.ActiveTags.Length > 1) then
error(Error(FSComp.SR.tcInvalidActivePatternName(), mBinding))
let isMultiCasePartialAP = memberFlagsOpt.IsNone && not apinfo.IsTotal && apinfo.ActiveTags.Length > 1
if isMultiCasePartialAP then
errorR(Error(FSComp.SR.tcPartialActivePattern(), m))
edgarfgp marked this conversation as resolved.
Show resolved Hide resolved

if Option.isSome memberFlagsOpt && not spatsL.IsEmpty then
errorR(Error(FSComp.SR.tcInvalidActivePatternName(apinfo.LogicalName), m))

apinfo.ActiveTagsWithRanges |> List.iteri (fun i (_tag, tagRange) ->
let item = Item.ActivePatternResult(apinfo, apOverallTy, i, tagRange)
Expand Down Expand Up @@ -12711,8 +12724,9 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind

let (SynValSig (attributes=Attributes synAttrs; explicitTypeParams=explicitTypeParams; isInline=isInline; isMutable=mutableFlag; xmlDoc=xmlDoc; accessibility=vis; synExpr=literalExprOpt; range=m)) = synValSig
let (ValTyparDecls (synTypars, _, synCanInferTypars)) = explicitTypeParams
let declaredTypars = TcTyparDecls cenv env synTypars

GeneralizationHelpers.CheckDeclaredTyparsPermitted(memFlagsOpt, synTypars, m)
GeneralizationHelpers.CheckDeclaredTyparsPermitted(memFlagsOpt, declaredTypars, m)

let canInferTypars = GeneralizationHelpers.ComputeCanInferExtraGeneralizableTypars (containerInfo.ParentRef, synCanInferTypars, memFlagsOpt)

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ tcUnnamedArgumentsDoNotFormPrefix,"The unnamed arguments do not form a prefix of
824,tcAttributesAreNotPermittedOnLetBindings,"Attributes are not permitted on 'let' bindings in expressions"
825,tcDefaultValueAttributeRequiresVal,"The 'DefaultValue' attribute may only be used on 'val' declarations"
826,tcConditionalAttributeRequiresMembers,"The 'ConditionalAttribute' attribute may only be used on members"
827,tcInvalidActivePatternName,"This is not a valid name for an active pattern"
827,tcInvalidActivePatternName,"'%s' is not a valid method name. Use a 'let' binding instead."
psfinaki marked this conversation as resolved.
Show resolved Hide resolved
828,tcEntryPointAttributeRequiresFunctionInModule,"The 'EntryPointAttribute' attribute may only be used on function definitions in modules"
829,tcMutableValuesCannotBeInline,"Mutable values cannot be marked 'inline'"
830,tcMutableValuesMayNotHaveGenericParameters,"Mutable values cannot have generic parameters"
Expand Down Expand Up @@ -1782,3 +1782,4 @@ featureEmptyBodiedComputationExpressions,"Support for computation expressions wi
featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modifiers to auto properties getters and setters"
3871,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint."
featureAllowObjectExpressionWithoutOverrides,"Allow object expressions without overrides"
3872,tcPartialActivePattern,"Multi-case partial active patterns are not supported. Consider using a single-case partial active pattern or a full active pattern."
8 changes: 8 additions & 0 deletions src/Compiler/SyntaxTree/PrettyNaming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,14 @@ type ActivePatternInfo =

member x.ActiveTagsWithRanges = let (APInfo(_, tags, _)) = x in tags

member x.LogicalName =
let (APInfo(isTotal, tags, _)) = x

tags
|> List.map fst
|> String.concat "|"
|> (fun s -> if isTotal then "(|" + s + "|)" else "(|" + s + "|_|)")

member x.Range = let (APInfo(_, _, m)) = x in m

let ActivePatternInfoOfValName nm (m: range) =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/SyntaxTree/PrettyNaming.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ type internal ActivePatternInfo =

member ActiveTags: string list
member ActiveTagsWithRanges: (string * range) list
member LogicalName: string
member IsTotal: bool
member Range: range

Expand Down
9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

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

9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.de.xlf

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

9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.es.xlf

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

9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

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

9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.it.xlf

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

9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

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

9 changes: 7 additions & 2 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

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

Loading
Loading