Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 36 additions & 37 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4291,8 +4291,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso
// #16621
match refinedItem with
| Item.Property(_, pinfos, _) ->
let propIdentRange = if rest.IsEmpty then (List.last lid).idRange else itemRange
RegisterUnionCaseTesterForProperty sink propIdentRange pinfos
RegisterUnionCaseTesterForProperty sink itemIdentRange pinfos
| _ -> ()

let callSinkWithSpecificOverload (minfo: MethInfo, pinfoOpt: PropInfo option, tpinst) =
Expand All @@ -4319,7 +4318,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso
callSink (item, emptyTyparInst)
AfterResolution.DoNothing

success (tinstEnclosing, item, itemRange, itemIdentRange, rest, afterResolution)
success (tinstEnclosing, item, itemIdentRange, rest, afterResolution)

[<return: Struct>]
let (|NonOverridable|_|) namedItem =
Expand Down Expand Up @@ -4367,8 +4366,7 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes
// #16621
match refinedItem with
| Item.Property(_, pinfos, _) ->
let propIdentRange = if rest.IsEmpty then (List.last lid).idRange else itemRange
RegisterUnionCaseTesterForProperty sink propIdentRange pinfos
RegisterUnionCaseTesterForProperty sink itemIdentRange pinfos
| _ -> ()

let callSinkWithSpecificOverload (minfo: MethInfo, pinfoOpt: PropInfo option, tpinst) =
Expand All @@ -4389,7 +4387,7 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes
callSink (unrefinedItem, emptyTyparInst)
AfterResolution.DoNothing

item, itemRange, itemIdentRange, rest, afterResolution
item, itemIdentRange, rest, afterResolution


//-------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/Checking/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ val internal ResolvePartialLongIdentToClassOrRecdFields:
val internal ResolveRecordOrClassFieldsOfType: NameResolver -> range -> AccessorDomain -> TType -> bool -> Item list

/// Resolve a long identifier occurring in an expression position.
/// Also returns the terminal identifier range for error diagnostics (#14284).
/// Returns the terminal identifier range for diagnostics and expression ranges (#14284).
val internal ResolveLongIdentAsExprAndComputeRange:
sink: TcResultsSink ->
ncenv: NameResolver ->
Expand All @@ -888,10 +888,10 @@ val internal ResolveLongIdentAsExprAndComputeRange:
typeNameResInfo: TypeNameResolutionInfo ->
lid: Ident list ->
maybeAppliedArgExpr: SynExpr option ->
ResultOrException<EnclosingTypeInst * Item * range * range * Ident list * AfterResolution>
ResultOrException<EnclosingTypeInst * Item * range * Ident list * AfterResolution>

/// Resolve a long identifier occurring in an expression position, qualified by a type.
/// Also returns the terminal identifier range for error diagnostics (#14284).
/// Returns the terminal identifier range for diagnostics and expression ranges (#14284).
val internal ResolveExprDotLongIdentAndComputeRange:
sink: TcResultsSink ->
ncenv: NameResolver ->
Expand All @@ -904,7 +904,7 @@ val internal ResolveExprDotLongIdentAndComputeRange:
findFlag: FindMemberFlag ->
staticOnly: bool ->
maybeAppliedArgExpr: SynExpr option ->
Item * range * range * Ident list * AfterResolution
Item * range * Ident list * AfterResolution

/// A generator of type instantiations used when no more specific type instantiation is known.
val FakeInstantiationGenerator: range -> Typar list -> TType list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ module AccessibilityAnnotations_Basic =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 1094, Line 18, Col 17, Line 18, Col 41, "The value 'somePrivateField' is not accessible from this code location")
(Error 1094, Line 19, Col 17, Line 19, Col 42, "The value 'somePrivateMethod' is not accessible from this code location")
(Error 1094, Line 18, Col 25, Line 18, Col 41, "The value 'somePrivateField' is not accessible from this code location")
(Error 1094, Line 19, Col 25, Line 19, Col 42, "The value 'somePrivateMethod' is not accessible from this code location")
(Error 491, Line 23, Col 17, Line 23, Col 34, "The member or object constructor 'PrivateMethod' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
]

Expand All @@ -70,11 +70,11 @@ module AccessibilityAnnotations_Basic =
|> shouldFail
|> withDiagnostics [
(Error 1092, Line 26, Col 19, Line 26, Col 32, "The type 'PrivateModule' is not accessible from this code location")
(Error 1094, Line 26, Col 17, Line 26, Col 34, "The value 'x' is not accessible from this code location")
(Error 1094, Line 26, Col 33, Line 26, Col 34, "The value 'x' is not accessible from this code location")
(Error 1092, Line 27, Col 19, Line 27, Col 32, "The type 'PrivateModule' is not accessible from this code location")
(Error 1094, Line 27, Col 17, Line 27, Col 34, "The value 'f' is not accessible from this code location")
(Error 1094, Line 29, Col 17, Line 29, Col 20, "The value 'y' is not accessible from this code location")
(Error 1094, Line 30, Col 17, Line 30, Col 20, "The value 'g' is not accessible from this code location")
(Error 1094, Line 27, Col 33, Line 27, Col 34, "The value 'f' is not accessible from this code location")
(Error 1094, Line 29, Col 19, Line 29, Col 20, "The value 'y' is not accessible from this code location")
(Error 1094, Line 30, Col 19, Line 30, Col 20, "The value 'g' is not accessible from this code location")
]

//SOURCE=E_privateThingsInaccessible03.fs SCFLAGS="--test:ErrorRanges" # E_privateThingsInaccessible03.fs
Expand All @@ -85,7 +85,7 @@ module AccessibilityAnnotations_Basic =
|> shouldFail
|> withDiagnostics [
(Error 1092, Line 11, Col 15, Line 11, Col 28, "The type 'PrivateModule' is not accessible from this code location")
(Error 1094, Line 11, Col 13, Line 11, Col 30, "The value 'x' is not accessible from this code location")
(Error 1094, Line 11, Col 29, Line 11, Col 30, "The value 'x' is not accessible from this code location")
(Error 39, Line 15, Col 13, Line 15, Col 26, "The value, namespace, type or module 'PrivateModule' is not defined.")
]

Expand All @@ -109,7 +109,7 @@ module AccessibilityAnnotations_Basic =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 1096, Line 11, Col 9, Line 11, Col 24, "The record, struct or class field 'foo' is not accessible from this code location")
(Error 1096, Line 11, Col 21, Line 11, Col 24, "The record, struct or class field 'foo' is not accessible from this code location")
]

//SOURCE=E_PrivateImplicitCtor01.fs SCFLAGS="--test:ErrorRanges" # E_PrivateImplicitCtor01.fs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ module AccessibilityAnnotations_OnTypeMembers =
(Error 491, Line 42, Col 19, Line 42, Col 26, "The member or object constructor 'test2' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 491, Line 42, Col 29, Line 42, Col 36, "The member or object constructor 'test5' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 491, Line 42, Col 40, Line 42, Col 47, "The member or object constructor 'test6' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 807, Line 42, Col 60, Line 42, Col 67, "Property 'test8' is not readable")
(Error 807, Line 42, Col 62, Line 42, Col 67, "Property 'test8' is not readable")
(Error 491, Line 43, Col 1, Line 43, Col 13, "The member or object constructor 'test3' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 491, Line 44, Col 1, Line 44, Col 13, "The member or object constructor 'test4' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 491, Line 45, Col 1, Line 45, Col 13, "The member or object constructor 'test5' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 491, Line 46, Col 1, Line 46, Col 13, "The member or object constructor 'test6' is not accessible. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.")
(Error 810, Line 47, Col 1, Line 47, Col 8, "Property 'test7' cannot be set")
(Error 810, Line 47, Col 3, Line 47, Col 8, "Property 'test7' cannot be set")
(Error 257, Line 47, Col 1, Line 47, Col 8, "Invalid mutation of a constant expression. Consider copying the expression to a mutable local, e.g. 'let mutable x = ...'.")
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ module ByrefSafetyAnalysis =
(Error 412, Line 178, Col 13, Line 178, Col 24, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 183, Col 9, Line 183, Col 20, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 187, Col 13, Line 187, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 187, Col 17, Line 187, Col 32, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 425, Line 187, Col 17, Line 187, Col 32, "The type of a first-class function cannot contain byrefs")
(Error 412, Line 187, Col 28, Line 187, Col 32, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 425, Line 187, Col 28, Line 187, Col 32, "The type of a first-class function cannot contain byrefs")
(Error 412, Line 191, Col 13, Line 191, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 193, Col 13, Line 193, Col 28, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 198, Col 9, Line 198, Col 24, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 193, Col 24, Line 193, Col 28, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 198, Col 20, Line 198, Col 24, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3301, Line 201, Col 9, Line 201, Col 15, "The function or method has an invalid return type 'byref<int> * int'. This is not permitted by the rules of Common IL.")
(Error 412, Line 203, Col 10, Line 203, Col 15, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 421, Line 203, Col 11, Line 203, Col 12, "The address of the variable 'x' cannot be used at this point")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ module RecordTypes =
|> withDiagnostics [
(Warning 464, Line 15, Col 22, Line 15, Col 28, "This code is less generic than indicated by its annotations. A unit-of-measure specified using '_' has been determined to be '1', i.e. dimensionless. Consider making the code generic, or removing the use of '_'.")
(Warning 464, Line 15, Col 35, Line 15, Col 42, "This code is less generic than indicated by its annotations. A unit-of-measure specified using '_' has been determined to be '1', i.e. dimensionless. Consider making the code generic, or removing the use of '_'.")
(Error 5, Line 17, Col 1, Line 17, Col 5, "This field is not mutable")
(Error 5, Line 17, Col 4, Line 17, Col 5, "This field is not mutable")
(Error 1, Line 17, Col 16, Line 17, Col 22, "The type 'float<Kg>' does not match the type 'decimal<Kg>'")
(Error 5, Line 18, Col 1, Line 18, Col 5, "This field is not mutable")
(Error 5, Line 18, Col 4, Line 18, Col 5, "This field is not mutable")
(Error 1, Line 18, Col 16, Line 18, Col 21, "This expression was expected to have type\n 'float' \nbut here has type\n 'decimal' ")
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ let _x3 = curryN f3 1 2 3
let private iwsamWarnings = [ "--nowarn:3536" ; "--nowarn:3535" ]

[<TheoryForNETCOREAPP>]
[<InlineData("static abstract Name : string", "ITest.Name", "get_Name", 3, 9, 3, 19)>]
[<InlineData("static abstract Name : string", "ITest.Name", "get_Name", 3, 15, 3, 19)>]
[<InlineData("static abstract Parse : string -> int", "ITest.Parse \"42\"", "Parse", 3, 9, 3, 25)>]
let ``Direct call to static abstract on interface produces error 3866`` (memberDef: string, call: string, memberName: string, l1, c1, l2, c2) =
Fsx $"type ITest =\n {memberDef}\nlet x = {call}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module UnionTypes =
|> shouldFail
|> withDiagnostics [
(Warning 1125, Line 11, Col 29, Line 11, Col 41, "The instantiation of the generic type 'list1' is missing and can't be inferred from the arguments or return type of this member. Consider providing a type instantiation when accessing this type, e.g. 'list1<_>'.")
(Error 3068, Line 15, Col 10, Line 15, Col 25, "The function or member 'toList' is used in a way that requires further type annotations at its definition to ensure consistency of inferred types. The inferred signature is 'static member private list1.toList: ('a list1 -> 'a list)'.")
(Error 3068, Line 15, Col 19, Line 15, Col 25, "The function or member 'toList' is used in a way that requires further type annotations at its definition to ensure consistency of inferred types. The inferred signature is 'static member private list1.toList: ('a list1 -> 'a list)'.")
]

//SOURCE=E_Interface_IComparable.fsx SCFLAGS="--test:ErrorRanges" # E_Interface_IComparable.fsx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module Baz =
]
]
VerifySequencePoints [
Line 6, Col 21, Line 6, Col 49
Line 6, Col 33, Line 6, Col 49
Line 8, Col 26, Line 8, Col 32
Line 16, Col 20, Line 16, Col 22
Line 21, Col 20, Line 21, Col 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let [<Literal>] x = System.Int32.MaxValue + 1
|> withResult {
Error = Error 3177
Range = { StartLine = 4
StartColumn = 21
StartColumn = 34
EndLine = 4
EndColumn = 46 }
Message = "This literal expression or attribute argument results in an arithmetic overflow."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ let main args =
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 1, Line 8, Col 25, Line 8, Col 37, "The tuples have differing lengths of 3 and 2")
(Error 1, Line 8, Col 29, Line 8, Col 37, "The tuples have differing lengths of 3 and 2")
]

module ``Not a function`` =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ let main _ =
|> compile
|> shouldFail
|> withDiagnostics [
Error 810, Line 9, Col 5, Line 9, Col 17, "Init-only property 'GetInit' cannot be set outside the initialization code. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization"
Error 810, Line 9, Col 10, Line 9, Col 17, "Init-only property 'GetInit' cannot be set outside the initialization code. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization"
]

[<FactForNETCOREAPP>]
Expand Down Expand Up @@ -209,7 +209,7 @@ let main _ =
|> compile
|> shouldFail
|> withDiagnostics [
Error 810, Line 9, Col 5, Line 9, Col 21, "Cannot call 'set_GetInit' - a setter for init-only property, please use object initialization instead. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization"
Error 810, Line 9, Col 10, Line 9, Col 21, "Cannot call 'set_GetInit' - a setter for init-only property, please use object initialization instead. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization"
]

[<FactForNETCOREAPP>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ type MyFSharpClass () =
|> compile
|> shouldFail
|> withDiagnostics [
(Error 810, Line 21, Col 9, Line 21, Col 33, "Property 'GetPublicSetPrivate' cannot be set")
(Error 807, Line 28, Col 17, Line 28, Col 41, "Property 'SetPublicGetPrivate' is not readable")]
(Error 810, Line 21, Col 14, Line 21, Col 33, "Property 'GetPublicSetPrivate' cannot be set")
(Error 807, Line 28, Col 22, Line 28, Col 41, "Property 'SetPublicGetPrivate' is not readable")]

[<Fact>]
let ``F# class F# non-derived class - access public`` () =
Expand Down Expand Up @@ -192,4 +192,4 @@ type MyFSharpClass () =
|> withReferences [csharpLib]
|> compile
|> shouldFail
|> withSingleDiagnostic (Error 810, Line 21, Col 9, Line 21, Col 31, "Property 'GetPublicSetPrivate' cannot be set")
|> withSingleDiagnostic (Error 810, Line 21, Col 12, Line 21, Col 31, "Property 'GetPublicSetPrivate' cannot be set")
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ let onlyIdC (ids: MyId list) = ids |> List.choose _.IdC
|> shouldFail
|> withDiagnostics [
(Error 23, Line 7, Col 17, Line 7, Col 20, "The member 'IdA' cannot be defined because the name 'IdA' clashes with the union case 'IdA' in this type or module");
(Error 812, Line 22, Col 51, Line 22, Col 56, "The syntax 'expr.id' may only be used with record labels, properties and fields");
(Error 812, Line 22, Col 53, Line 22, Col 56, "The syntax 'expr.id' may only be used with record labels, properties and fields");
(Error 23, Line 17, Col 17, Line 17, Col 20, "The member 'IdC' cannot be defined because the name 'IdC' clashes with the union case 'IdC' in this type or module");
(Error 812, Line 24, Col 51, Line 24, Col 56, "The syntax 'expr.id' may only be used with record labels, properties and fields")
(Error 812, Line 24, Col 53, Line 24, Col 56, "The syntax 'expr.id' may only be used with record labels, properties and fields")
]
Loading
Loading