Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1936874

Browse files
committed
Adjust parser to disallow vertical pipes in active pattern case identifiers.
Related todotnet#78 - without this restriction, the typechecker can't distinguish between valid pipes separating cases and invalid pipes that are embedded in a case identifier. The result is that nonsense like this compiles, when it should not:let (|``Foo|Bar``|) x = match x with | 0 -> Foo | _ -> Barmatch 42 with| Foo -> "foo"| Bar -> "bar" (changeset 1282321)
1 parent14f88dd commit1936874

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ parsMultiArgumentGenericTypeFormDeprecated,"The syntax '(typ,...,typ) ident' is
475475
621,parsUnexpectedTypeParameter,"Syntax error: unexpected type parameter specification"
476476
622,parsMismatchedQuotationName,"Mismatched quotation operator name, beginning with '%s'"
477477
623,parsActivePatternCaseMustBeginWithUpperCase,"Active pattern case identifiers must begin with an uppercase letter"
478+
624,parsActivePatternCaseContainsPipe,"The '|' character is not permitted in active pattern case identifiers"
478479
parsNoEqualShouldFollowNamespace,"No '=' symbol should follow a 'namespace' declaration"
479480
parsSyntaxModuleStructEndDeprecated,"The syntax 'module ... = struct .. end' is not used in F# code. Consider using 'module ... = begin .. end'"
480481
parsSyntaxModuleSigEndDeprecated,"The syntax 'module ... : sig .. end' is not used in F# code. Consider using 'module ... = begin .. end'"

‎src/fsharp/pars.fsy‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,6 +4159,7 @@ operatorName:
41594159
barName:
41604160
| IDENT
41614161
{ if not (String.isUpper $1) then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsActivePatternCaseMustBeginWithUpperCase());
4162+
if ($1.IndexOf('|') <> -1) then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsActivePatternCaseContainsPipe());
41624163
$1 }
41634164

41644165
barNames:
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
// #Regression #Conformance #PatternMatching #ActivePatterns
22
// Verify error if Active Patterns do not start with an upper case letter
3-
//<Expects id="FS0623" status="error" span="(6,7)">Active pattern case identifiers must begin with an uppercase letter</Expects>
4-
//<Expects id="FS0623" status="error" span="(6,16)">Active pattern case identifiers must begin with an uppercase letter</Expects>
3+
//<Expects id="FS0623" status="error" span="(11,7)">Active pattern case identifiers must begin with an uppercase letter</Expects>
4+
//<Expects id="FS0623" status="error" span="(11,16)">Active pattern case identifiers must begin with an uppercase letter</Expects>
5+
//<Expects id="FS0623" status="error" span="(12,7)">Active pattern case identifiers must begin with an uppercase letter</Expects>
6+
//<Expects id="FS0623" status="error" span="(13,10)">Active pattern case identifiers must begin with an uppercase letter</Expects>
7+
//<Expects id="FS0623" status="error" span="(14,7)">Active pattern case identifiers must begin with an uppercase letter</Expects>
8+
//<Expects id="FS0624" status="error" span="(15,7)">The '\|' character is not permitted in active pattern case identifiers</Expects>
9+
//<Expects id="FS0624" status="error" span="(16,9)">The '\|' character is not permitted in active pattern case identifiers</Expects>
510

611
let(|positive|negative|)n=if n<0then positiveelse negative
12+
let(|`` A``|)(x:int)= x
13+
let(|B1|``+B2``|)(x:int)=if x=0then OneAelse``+B2``
14+
let(|`` C``|_|)(x:int)=if x=0then Some(x)else None
15+
let(|``D|E``|F|)(x:int)=if x=0then Delif x=1then Eelse F
16+
let(|G|``H||I``|)(x:int)=if x=0then Gelif x=1then Helse``|I``
717

818
exit1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp