Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4629,7 +4629,7 @@ let rec encodeCustomAttrElemTypeForObject x =
| ILAttribElem.UInt64 _ -> [| et_U8 |]
| ILAttribElem.Type _ -> [| 0x50uy |]
| ILAttribElem.TypeRef _ -> [| 0x50uy |]
| ILAttribElem.Null _ -> [| et_STRING |] // yes, the 0xe prefix is used when passing a "null" to a property or argument of type "object" here
| ILAttribElem.Null -> [| et_STRING |] // yes, the 0xe prefix is used when passing a "null" to a property or argument of type "object" here
| ILAttribElem.Single _ -> [| et_R4 |]
| ILAttribElem.Double _ -> [| et_R8 |]
| ILAttribElem.Array (elemTy, _) -> [| yield et_SZARRAY; yield! encodeCustomAttrElemType elemTy |]
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/AbstractIL/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ let convTypeRefAux (cenv: cenv) (tref: ILTypeRef) =
match tref.Scope with
| ILScopeRef.Assembly asmref -> convResolveAssemblyRef cenv asmref qualifiedName
| ILScopeRef.Module _
| ILScopeRef.Local _ ->
| ILScopeRef.Local ->
let typT = Type.GetType qualifiedName

match typT with
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9905,7 +9905,7 @@ and TcMethodArg cenv env (lambdaPropagationInfo, tpenv) (lambdaPropagationInfoFo
let lambdaPropagationInfo =
[| for info, argInfo in Array.zip lambdaPropagationInfo lambdaPropagationInfoForArg do
match argInfo with
| ArgDoesNotMatch _ -> ()
| ArgDoesNotMatch -> ()
| NoInfo | CallerLambdaHasArgTypes _ ->
yield info
| CalledArgMatchesType (adjustedCalledArgTy, noEagerConstraintApplication) ->
Expand Down
18 changes: 14 additions & 4 deletions src/Compiler/Checking/CheckPatterns.fs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,15 @@ and TcPatLongIdentUnionCaseOrExnCase warnOnUpper cenv env ad vFlags patEnv ty (m

let args, extraPatternsFromNames =
match args with
| SynArgPats.Pats args -> args, []
| SynArgPats.Pats args ->
if g.langVersion.SupportsFeature(LanguageFeature.MatchNotAllowedForUnionCaseWithNoData) then
match args with
| [ SynPat.Wild _ ] | [ SynPat.Named _ ] when argNames.IsEmpty ->
warning(Error(FSComp.SR.matchNotAllowedForUnionCaseWithNoData(), m))
args, []
| _ -> args, []
else
args, []
| SynArgPats.NamePatPairs (pairs, m, _) ->
// rewrite patterns from the form (name-N = pat-N; ...) to (..._, pat-N, _...)
// so type T = Case of name: int * value: int
Expand Down Expand Up @@ -661,10 +669,12 @@ and TcPatLongIdentUnionCaseOrExnCase warnOnUpper cenv env ad vFlags patEnv ty (m
// note: we allow both 'C _' and 'C (_)' regardless of number of argument of the pattern
| [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> List.replicate numArgTys e, []


| args when numArgTys = 0 ->
errorR (Error (FSComp.SR.tcUnionCaseDoesNotTakeArguments (), m))
[], args
if g.langVersion.SupportsFeature(LanguageFeature.MatchNotAllowedForUnionCaseWithNoData) then
[], args
else
errorR (Error (FSComp.SR.tcUnionCaseDoesNotTakeArguments (), m))
[], args

| arg :: rest when numArgTys = 1 ->
if numArgTys = 1 && not (List.isEmpty rest) then
Expand Down
12 changes: 6 additions & 6 deletions src/Compiler/Checking/PatternMatchCompilation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -648,9 +648,9 @@ let isDiscrimSubsumedBy g amap m discrim taken =
match taken, discrim with
| DecisionTreeTest.IsInst (_, tgtTy1), DecisionTreeTest.IsInst (_, tgtTy2) ->
computeWhatFailingTypeTestImpliesAboutTypeTest g amap m tgtTy1 tgtTy2 = Implication.Fails
| DecisionTreeTest.IsNull _, DecisionTreeTest.IsInst (_, tgtTy2) ->
| DecisionTreeTest.IsNull, DecisionTreeTest.IsInst (_, tgtTy2) ->
computeWhatFailingNullTestImpliesAboutTypeTest g tgtTy2 = Implication.Fails
| DecisionTreeTest.IsInst (_, tgtTy1), DecisionTreeTest.IsNull _ ->
| DecisionTreeTest.IsInst (_, tgtTy1), DecisionTreeTest.IsNull ->
computeWhatFailingTypeTestImpliesAboutNullTest g tgtTy1 = Implication.Fails
| _ ->
false
Expand Down Expand Up @@ -690,15 +690,15 @@ let discrimWithinSimultaneousClass g amap m discrim prev =
// Check that each previous test in the set, if successful, gives some information about this test
prev |> List.forall (fun edge ->
match edge with
| DecisionTreeTest.IsNull _ -> true
| DecisionTreeTest.IsNull -> true
| DecisionTreeTest.IsInst (_, tgtTy1) -> computeWhatSuccessfulTypeTestImpliesAboutNullTest g tgtTy1 <> Implication.Nothing
| _ -> false)

| DecisionTreeTest.IsInst (_, tgtTy2), _ ->
// Check that each previous test in the set, if successful, gives some information about this test
prev |> List.forall (fun edge ->
match edge with
| DecisionTreeTest.IsNull _ -> true
| DecisionTreeTest.IsNull -> true
| DecisionTreeTest.IsInst (_, tgtTy1) -> computeWhatSuccessfulTypeTestImpliesAboutTypeTest g amap m tgtTy1 tgtTy2 <> Implication.Nothing
| _ -> false)

Expand Down Expand Up @@ -1501,7 +1501,7 @@ let CompilePatternBasic
// F# exception definitions are sealed.
[]

| DecisionTreeTest.IsNull _ ->
| DecisionTreeTest.IsNull ->
match computeWhatSuccessfulNullTestImpliesAboutTypeTest g tgtTy1 with
| Implication.Succeeds -> [Frontier (i, newActives, valMap)]
| Implication.Fails -> []
Expand Down Expand Up @@ -1537,7 +1537,7 @@ let CompilePatternBasic
| Implication.Nothing ->
[frontier]

| DecisionTreeTest.IsNull _ ->
| DecisionTreeTest.IsNull ->
match computeWhatSuccessfulNullTestImpliesAboutTypeTest g tgtTy1 with
| Implication.Succeeds -> [Frontier (i, newActives, valMap)]
| Implication.Fails -> []
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ let CheckTypeInstNoInnerByrefs cenv env m tyargs =
/// Applied functions get wrapped in coerce nodes for subsumption coercions
let (|OptionalCoerce|) expr =
match stripDebugPoints expr with
| Expr.Op (TOp.Coerce _, _, [DebugPoints(Expr.App (f, _, _, [], _), _)], _) -> f
| Expr.Op (TOp.Coerce, _, [DebugPoints(Expr.App (f, _, _, [], _), _)], _) -> f
| _ -> expr

/// Check an expression doesn't contain a 'reraise'
Expand Down Expand Up @@ -1539,7 +1539,7 @@ and CheckExprOp cenv env (op, tyargs, args, m) ctxt expr =
else
{ scope = 1; flags = LimitFlags.None }

| TOp.LValueOp (LSet _, vref), _, [arg] ->
| TOp.LValueOp (LSet, vref), _, [arg] ->
let isVrefLimited = not (HasLimitFlag LimitFlags.StackReferringSpanLike (GetLimitVal cenv env m vref.Deref))
let isArgLimited = HasLimitFlag LimitFlags.StackReferringSpanLike (CheckExprPermitByRefLike cenv env arg)
if isVrefLimited && isArgLimited then
Expand Down Expand Up @@ -1901,7 +1901,7 @@ and CheckAttribArgExpr cenv env expr =
| Const.Double _
| Const.Single _
| Const.Char _
| Const.Zero _
| Const.Zero
| Const.String _ -> ()
| _ ->
if cenv.reportErrors then
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4150,7 +4150,7 @@ and GenApp (cenv: cenv) cgbuf eenv (f, fty, tyargs, curriedArgs, m) sequel =
| Expr.Val (v, _, m), _, [ arg ] when valRefEq g v g.methodhandleof_vref ->
let (|OptionalCoerce|) x =
match stripDebugPoints x with
| Expr.Op (TOp.Coerce _, _, [ arg ], _) -> arg
| Expr.Op (TOp.Coerce, _, [ arg ], _) -> arg
| x -> x

let (|OptionalTyapp|) x =
Expand Down Expand Up @@ -4695,7 +4695,7 @@ and eligibleForFilter (cenv: cenv) expr =
| Expr.Op (TOp.UnionCaseFieldGet _, _, _, _) -> true
| Expr.Op (TOp.ValFieldGet _, _, _, _) -> true
| Expr.Op (TOp.TupleFieldGet _, _, _, _) -> true
| Expr.Op (TOp.Coerce _, _, _, _) -> true
| Expr.Op (TOp.Coerce, _, _, _) -> true
| Expr.Val _ -> true
| _ -> false

Expand Down Expand Up @@ -7587,7 +7587,7 @@ and GenDecisionTreeSwitch

// Use GenDecisionTreeTest to generate a single test for null (when no box required) where the success
// is going to the immediate first node in the tree
| TCase (DecisionTreeTest.IsNull _, (TDSuccess ([], 0) as successTree)) :: rest when
| TCase (DecisionTreeTest.IsNull, (TDSuccess ([], 0) as successTree)) :: rest when
rest.Length = (match defaultTargetOpt with
| None -> 1
| Some _ -> 0)
Expand Down
7 changes: 4 additions & 3 deletions src/Compiler/Driver/CompilerDiagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ type Exception with
// 24 cannot be reused
| PatternMatchCompilation.MatchIncomplete _ -> 25
| PatternMatchCompilation.RuleNeverMatched _ -> 26

| ValNotMutable _ -> 27
| ValNotLocal _ -> 28
| MissingFields _ -> 29
Expand Down Expand Up @@ -1083,7 +1084,7 @@ type Exception with
| Parser.TOKEN_BAR_RBRACK -> SR.GetString("Parser.TOKEN.BAR.RBRACK")
| Parser.TOKEN_BAR_RBRACE -> SR.GetString("Parser.TOKEN.BAR.RBRACE")
| Parser.TOKEN_GREATER_RBRACK -> SR.GetString("Parser.TOKEN.GREATER.RBRACK")
| Parser.TOKEN_RQUOTE_DOT _
| Parser.TOKEN_RQUOTE_DOT
| Parser.TOKEN_RQUOTE -> SR.GetString("Parser.TOKEN.RQUOTE")
| Parser.TOKEN_RBRACK -> SR.GetString("Parser.TOKEN.RBRACK")
| Parser.TOKEN_RBRACE
Expand All @@ -1110,8 +1111,8 @@ type Exception with
| Parser.TOKEN_OTHEN -> SR.GetString("Parser.TOKEN.OTHEN")
| Parser.TOKEN_ELSE
| Parser.TOKEN_OELSE -> SR.GetString("Parser.TOKEN.OELSE")
| Parser.TOKEN_LET _
| Parser.TOKEN_OLET _ -> SR.GetString("Parser.TOKEN.OLET")
| Parser.TOKEN_LET
| Parser.TOKEN_OLET -> SR.GetString("Parser.TOKEN.OLET")
| Parser.TOKEN_OBINDER
| Parser.TOKEN_BINDER -> SR.GetString("Parser.TOKEN.BINDER")
| Parser.TOKEN_OAND_BANG
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@ featureSelfTypeConstraints,"self type constraints"
featureRequiredProperties,"support for required properties"
featureInitProperties,"support for consuming init properties"
featureLowercaseDUWhenRequireQualifiedAccess,"Allow lowercase DU when RequireQualifiedAccess attribute"
featureMatchNotAllowedForUnionCaseWithNoData,"Pattern match discard is not allowed for union case that takes no data."
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
Expand Down Expand Up @@ -1654,3 +1655,4 @@ reprStateMachineInvalidForm,"The state machine has an unexpected form"
3545,tcMissingRequiredMembers,"The following required properties have to be initalized:%s"
3546,parsExpectingPatternInTuple,"Expecting pattern"
3547,parsExpectedPatternAfterToken,"Expected a pattern after this point"
3548,matchNotAllowedForUnionCaseWithNoData,"Pattern discard is not allowed for union case that takes no data."
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type LanguageFeature =
| LowercaseDUWhenRequireQualifiedAccess
| InterfacesWithAbstractStaticMembers
| SelfTypeConstraints
| MatchNotAllowedForUnionCaseWithNoData

/// LanguageVersion management
type LanguageVersion(versionText) =
Expand Down Expand Up @@ -124,6 +125,7 @@ type LanguageVersion(versionText) =

// F# preview
LanguageFeature.FromEndSlicing, previewVersion
LanguageFeature.MatchNotAllowedForUnionCaseWithNoData, previewVersion
]

static let defaultLanguageVersion = LanguageVersion("default")
Expand Down Expand Up @@ -230,6 +232,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.LowercaseDUWhenRequireQualifiedAccess -> FSComp.SR.featureLowercaseDUWhenRequireQualifiedAccess ()
| LanguageFeature.InterfacesWithAbstractStaticMembers -> FSComp.SR.featureInterfacesWithAbstractStaticMembers ()
| LanguageFeature.SelfTypeConstraints -> FSComp.SR.featureSelfTypeConstraints ()
| LanguageFeature.MatchNotAllowedForUnionCaseWithNoData -> FSComp.SR.featureMatchNotAllowedForUnionCaseWithNoData ()

/// Get a version string associated with the given feature.
static member GetFeatureVersionString feature =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type LanguageFeature =
| LowercaseDUWhenRequireQualifiedAccess
| InterfacesWithAbstractStaticMembers
| SelfTypeConstraints
| MatchNotAllowedForUnionCaseWithNoData

/// LanguageVersion management
type LanguageVersion =
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ type ILMultiInMemoryAssemblyEmitEnv(
| ILScopeRef.Assembly asmref ->
convResolveAssemblyRef asmref qualifiedName
| ILScopeRef.Module _
| ILScopeRef.Local _ ->
| ILScopeRef.Local ->
let typT = Type.GetType qualifiedName
match typT with
| null -> error(Error(FSComp.SR.itemNotFoundDuringDynamicCodeGen ("type", qualifiedName, "<emitted>"), range0))
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Optimize/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ let IsKnownOnlyMutableBeforeUse (vref: ValRef) =

let IsDiscardableEffectExpr expr =
match stripDebugPoints expr with
| Expr.Op (TOp.LValueOp (LByrefGet _, _), [], [], _) -> true
| Expr.Op (TOp.LValueOp (LByrefGet, _), [], [], _) -> true
| _ -> false

/// Checks is a value binding is non-discardable
Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/Service/SemanticClassification.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module TcResolutionsExtensions =
| TFSharpInterface -> SemanticClassificationType.Interface
| TFSharpStruct -> SemanticClassificationType.ValueType
| TFSharpDelegate _ -> SemanticClassificationType.Delegate
| TFSharpEnum _ -> SemanticClassificationType.Enumeration
| TFSharpEnum -> SemanticClassificationType.Enumeration
| TFSharpRecdRepr _
| TFSharpUnionRepr _ ->
if isStructTyconRef g tcref then
Expand Down Expand Up @@ -149,9 +149,9 @@ module TcResolutionsExtensions =
match occ with
| ItemOccurence.UseInType
| ItemOccurence.UseInAttribute
| ItemOccurence.Use _
| ItemOccurence.Binding _
| ItemOccurence.Pattern _
| ItemOccurence.Use
| ItemOccurence.Binding
| ItemOccurence.Pattern
| ItemOccurence.Open -> Some()
| _ -> None

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceDeclarationLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ module internal DescriptionListsImpl =
| TFSharpInterface -> FSharpGlyph.Interface
| TFSharpStruct -> FSharpGlyph.Struct
| TFSharpDelegate _ -> FSharpGlyph.Delegate
| TFSharpEnum _ -> FSharpGlyph.Enum
| TFSharpEnum -> FSharpGlyph.Enum
| TFSharpRecdRepr _ -> FSharpGlyph.Type
| TFSharpUnionRepr _ -> FSharpGlyph.Union
| TILObjectRepr (TILObjectReprData (_, _, td)) ->
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,7 @@ type FSharpType(cenv, ty:TType) =
isResolved() &&
protect <| fun () ->
match stripTyparEqns ty with
| TType_app _ | TType_measure (Measure.Const _ | Measure.Prod _ | Measure.Inv _ | Measure.One _) -> true
| TType_app _ | TType_measure (Measure.Const _ | Measure.Prod _ | Measure.Inv _ | Measure.One) -> true
| _ -> false

member _.IsTupleType =
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6049,7 +6049,7 @@ and remapTyconRepr ctxt tmenv repr =
let ctxt = st.Context.RemapTyconRefs(unbox >> remapTyconRef tmenv.tyconRefRemap >> box)
ProvidedType.ApplyContext (st, ctxt)) }
#endif
| TNoRepr _ -> repr
| TNoRepr -> repr
| TAsmRepr _ -> repr
| TMeasureableRepr x -> TMeasureableRepr (remapType tmenv x)

Expand Down Expand Up @@ -9684,10 +9684,10 @@ let rec EvalAttribArgExpr g x =
| Const.Double _
| Const.Single _
| Const.Char _
| Const.Zero _
| Const.Zero
| Const.String _ ->
x
| Const.Decimal _ | Const.IntPtr _ | Const.UIntPtr _ | Const.Unit _ ->
| Const.Decimal _ | Const.IntPtr _ | Const.UIntPtr _ | Const.Unit ->
errorR (Error ( FSComp.SR.tastNotAConstantExpression(), m))
x

Expand Down
10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@
<target state="translated">Revize kompatibility ML</target>
<note />
</trans-unit>
<trans-unit id="featureMatchNotAllowedForUnionCaseWithNoData">
<source>Pattern match discard is not allowed for union case that takes no data.</source>
<target state="new">Pattern match discard is not allowed for union case that takes no data.</target>
<note />
</trans-unit>
<trans-unit id="featureNameOf">
<source>nameof</source>
<target state="translated">nameof</target>
Expand Down Expand Up @@ -402,6 +407,11 @@
<target state="translated">Neplatný interpolovaný řetězec. V interpolovaných výrazech se nedají použít řetězcové literály s trojitými uvozovkami. Zvažte možnost použít pro interpolovaný výraz explicitní vazbu let.</target>
<note />
</trans-unit>
<trans-unit id="matchNotAllowedForUnionCaseWithNoData">
<source>Pattern discard is not allowed for union case that takes no data.</source>
<target state="new">Pattern discard is not allowed for union case that takes no data.</target>
<note />
</trans-unit>
<trans-unit id="mlCompatError">
<source>This construct is deprecated. {0}. You can enable this feature by using '--langversion:5.0' and '--mlcompatibility'.</source>
<target state="translated">Tento konstruktor je zastaralý. {0}. Tuto funkci můžete povolit pomocí parametrů --langversion:5.0 a --mlcompatibility.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@
<target state="translated">ML-Kompatibilitätsrevisionen</target>
<note />
</trans-unit>
<trans-unit id="featureMatchNotAllowedForUnionCaseWithNoData">
<source>Pattern match discard is not allowed for union case that takes no data.</source>
<target state="new">Pattern match discard is not allowed for union case that takes no data.</target>
<note />
</trans-unit>
<trans-unit id="featureNameOf">
<source>nameof</source>
<target state="translated">nameof</target>
Expand Down Expand Up @@ -402,6 +407,11 @@
<target state="translated">Ungültige interpolierte Zeichenfolge. Zeichenfolgenliterale mit dreifachen Anführungszeichen dürfen in interpolierten Ausdrücken nicht verwendet werden. Erwägen Sie die Verwendung einer expliziten let-Bindung für den Interpolationsausdruck.</target>
<note />
</trans-unit>
<trans-unit id="matchNotAllowedForUnionCaseWithNoData">
<source>Pattern discard is not allowed for union case that takes no data.</source>
<target state="new">Pattern discard is not allowed for union case that takes no data.</target>
<note />
</trans-unit>
<trans-unit id="mlCompatError">
<source>This construct is deprecated. {0}. You can enable this feature by using '--langversion:5.0' and '--mlcompatibility'.</source>
<target state="translated">Dieses Konstrukt ist veraltet. {0}. Sie können dieses Feature mithilfe von „--langversion:5.0“ und „--mlcompatibility“ aktivieren.</target>
Expand Down
Loading