Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aafdb02
Attempt add match! syntax to parser (as normal match) (does not work)
jwosty Mar 2, 2018
958a208
Add name for MATCH_BANG token ("keyword 'match!')
jwosty Mar 3, 2018
53a67cb
Make match! valid in (and only in) computational expressions
jwosty Mar 3, 2018
96f297b
match! works
jwosty Mar 4, 2018
a3bcd93
Merge remote-tracking branch 'upstream/master' into match-bang
jwosty Mar 4, 2018
8d9ee1b
Add match! to xlf localization files
jwosty Mar 4, 2018
a3e40e0
Add two tests for match!
jwosty Mar 5, 2018
582efb0
Don't use left-pipe
jwosty Mar 5, 2018
353435a
Give match! keyword a description
jwosty Mar 5, 2018
8dc2e5c
Fix syntax error, and change match! description
jwosty Mar 5, 2018
6f21ec7
xlf updated
jindraivanek Mar 7, 2018
4dc2a31
Merge pull request #1 from jindraivanek/xlf
jwosty Mar 7, 2018
772bf52
Add match! keyword description to resx
jwosty Mar 7, 2018
2593cf4
Update FSComp.fs
jwosty Mar 7, 2018
9e6f2dc
Write quotation test for match!
jwosty Mar 7, 2018
c1fd9a8
First crack at compile error tests
jwosty Mar 9, 2018
cb6ea74
Fix baselines
jwosty Mar 9, 2018
596c84e
Fix baseline one more time
jwosty Mar 9, 2018
63ef27b
Add vs baseline
jwosty Mar 9, 2018
0a09ded
Merge branch 'master' into match-bang
jwosty Mar 13, 2018
4308cd0
Merge branch 'master' into match-bang
jwosty Mar 24, 2018
9888a55
Fix merge mistake
jwosty Mar 24, 2018
44f76ba
Fix merge mistake (#2)
Nhowka Apr 2, 2018
a94123e
Fix merge mistake in tests
jwosty Apr 2, 2018
0ef4996
Merge branch 'master' into match-bang
jwosty Apr 10, 2018
fc7916f
Merge branch 'master' into match-bang
jwosty May 21, 2018
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
Prev Previous commit
Next Next commit
Make match! valid in (and only in) computational expressions
  • Loading branch information
jwosty committed Mar 3, 2018
commit 53a67cbed2ccc25d6e7e19c3a7281da3d1e61106
2 changes: 1 addition & 1 deletion src/fsharp/LexFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ type LexFilterImpl (lightSyntaxStatus:LightSyntaxStatus, compilingFsLib, lexer,
pushCtxt tokenTup (CtxtIf (tokenStartPos))
returnToken tokenLexbufState token

| MATCH, _ ->
| (MATCH | MATCH_BANG), _ ->
if debug then dprintf "MATCH, pushing CtxtMatch(%a)\n" outputPos tokenStartPos
pushCtxt tokenTup (CtxtMatch (tokenStartPos))
returnToken tokenLexbufState token
Expand Down
26 changes: 15 additions & 11 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3505,7 +3505,8 @@ let (|SimpleSemicolonSequence|_|) acceptDeprecated c =
| SynExpr.Sequential (_, _, e1, e2, _) -> YieldFree e1 && YieldFree e2
| SynExpr.IfThenElse (_, e2, e3opt, _, _, _, _) -> YieldFree e2 && Option.forall YieldFree e3opt
| SynExpr.TryWith (e1, _, clauses, _, _, _, _) -> YieldFree e1 && clauses |> List.forall (fun (Clause(_, _, e, _, _)) -> YieldFree e)
| SynExpr.Match (_, _, clauses, _, _) -> clauses |> List.forall (fun (Clause(_, _, e, _, _)) -> YieldFree e)
| (SynExpr.Match (_, _, clauses, _, _) | SynExpr.MatchBang (_, _, clauses, _, _)) ->
clauses |> List.forall (fun (Clause(_, _, e, _, _)) -> YieldFree e)
| SynExpr.For (_, _, _, _, _, body, _)
| SynExpr.TryFinally (body, _, _, _, _)
| SynExpr.LetOrUse (_, _, _, body, _)
Expand All @@ -3531,6 +3532,7 @@ let (|SimpleSemicolonSequence|_|) acceptDeprecated c =
| SynExpr.YieldOrReturn _
| SynExpr.LetOrUse _
| SynExpr.Do _
| SynExpr.MatchBang _
| SynExpr.LetOrUseBang _
| SynExpr.ImplicitZero _
| SynExpr.While _ -> false
Expand Down Expand Up @@ -6087,23 +6089,19 @@ and TcExprUndelayed cenv overallTy env tpenv (expr: SynExpr) =

| SynExpr.YieldOrReturn ((isTrueYield, _), _, m)
| SynExpr.YieldOrReturnFrom ((isTrueYield, _), _, m) when isTrueYield ->
error(Error(FSComp.SR.tcConstructRequiresListArrayOrSequence(), m))
error(Error(FSComp.SR.tcConstructRequiresListArrayOrSequence(), m))
| SynExpr.YieldOrReturn ((_, isTrueReturn), _, m)
| SynExpr.YieldOrReturnFrom ((_, isTrueReturn), _, m) when isTrueReturn ->
error(Error(FSComp.SR.tcConstructRequiresComputationExpressions(), m))
error(Error(FSComp.SR.tcConstructRequiresComputationExpressions(), m))
| SynExpr.YieldOrReturn (_, _, m)
| SynExpr.YieldOrReturnFrom (_, _, m)
| SynExpr.ImplicitZero m ->
error(Error(FSComp.SR.tcConstructRequiresSequenceOrComputations(), m))
error(Error(FSComp.SR.tcConstructRequiresSequenceOrComputations(), m))
| SynExpr.DoBang (_, m)
| SynExpr.LetOrUseBang (_, _, _, _, _, _, m) ->
error(Error(FSComp.SR.tcConstructRequiresComputationExpression(), m))
| SynExpr.MatchBang (spMatch, x, matches, isExnMatch, _m) ->

let x', inputTy, tpenv = TcExprOfUnknownType cenv env tpenv x
let mExpr = x'.Range
let v, e, tpenv = TcAndPatternCompileMatchClauses mExpr mExpr (if isExnMatch then Throw else ThrowIncompleteMatchException) cenv inputTy overallTy env tpenv matches
(mkLet spMatch mExpr v x' e, tpenv)
error(Error(FSComp.SR.tcConstructRequiresComputationExpression(), m))
| SynExpr.MatchBang (_, _, _, _, m) ->
error(Error(FSComp.SR.tcConstructRequiresComputationExpression(), m))

/// Check lambdas as a group, to catch duplicate names in patterns
and TcIteratedLambdas cenv isFirst (env: TcEnv) overallTy takenNames tpenv e =
Expand Down Expand Up @@ -8009,6 +8007,12 @@ and TcComputationExpression cenv env overallTy mWhole interpExpr builderTy tpenv
let clauses = clauses |> List.map (fun (Clause(pat, cond, innerComp, patm, sp)) -> Clause(pat, cond, transNoQueryOps innerComp, patm, sp))
Some(translatedCtxt (SynExpr.Match(spMatch, expr, clauses, false, m)))

| SynExpr.MatchBang (spMatch, expr, clauses, false, m) ->
let mMatch = match spMatch with SequencePointAtBinding mMatch -> mMatch | _ -> m
if isQuery then error(Error(FSComp.SR.tcMatchMayNotBeUsedWithQuery(), mMatch))
let clauses = clauses |> List.map (fun (Clause(pat, cond, innerComp, patm, sp)) -> Clause(pat, cond, transNoQueryOps innerComp, patm, sp))
Some(translatedCtxt (SynExpr.Match(spMatch, expr, clauses, false, m)))

| SynExpr.TryWith (innerComp, _mTryToWith, clauses, _mWithToLast, mTryToLast, spTry, _spWith) ->
let mTry = match spTry with SequencePointAtTry(m) -> m | _ -> mTryToLast

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -3055,7 +3055,7 @@ declExpr:
{ let mMatch = (rhs parseState 1)
let mWith,(clauses,mLast) = $3
let spBind = SequencePointAtBinding(unionRanges mMatch mWith)
SynExpr.Match(spBind, $2,clauses,false,unionRanges mMatch mLast) }
SynExpr.MatchBang(spBind, $2,clauses,false,unionRanges mMatch mLast) }

| MATCH_BANG typedSeqExpr recover %prec expr_match
{ if not $3 then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedEndOfFileMatch())
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/service/ServiceUntypedParse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,8 @@ module UntypedParseImpl =
| SynExpr.JoinIn(e1, _, e2, _) -> List.tryPick (walkExprWithKind parentKind) [e1; e2]
| SynExpr.YieldOrReturn(_, e, _) -> walkExprWithKind parentKind e
| SynExpr.YieldOrReturnFrom(_, e, _) -> walkExprWithKind parentKind e
| (SynExpr.Match(_, e, synMatchClauseList, _, _) | SynExpr.MatchBang(_, e, synMatchClauseList, _, _)) ->
walkExprWithKind parentKind e |> Option.orElse (List.tryPick walkClause synMatchClauseList)
| SynExpr.LetOrUseBang(_, _, _, _, e1, e2, _) -> List.tryPick (walkExprWithKind parentKind) [e1; e2]
| SynExpr.DoBang(e, _) -> walkExprWithKind parentKind e
| SynExpr.TraitCall (ts, sign, e, _) ->
Expand Down