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

Commit6300f06

Browse files
forkidsyme
authored andcommitted
Improve FS0512, FS0529, FS0537 (#2988)
* Improve FS0512* Improve FS0529* Improve FS0537* DoCannotHaveVisibilityDeclarations test* ModuleAbbreviationsArePrivate test
1 parent3f155eb commit6300f06

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ csNoOverloadsFound,"No overloads match for method '%s'."
358358
csMethodIsOverloaded,"A unique overload for method '%s' could not be determined based on type information prior to this program point. A type annotation may be needed."
359359
csCandidates,"Candidates: %s"
360360
csSeeAvailableOverloads,"The available overloads are shown below (or in the Error List window)."
361-
512,parsDoCannotHaveVisibilityDeclarations,"Accessibility modifiers are not permitted on 'do' bindings"
361+
512,parsDoCannotHaveVisibilityDeclarations,"Accessibility modifiers are not permitted on 'do' bindings, but '%s' was given."
362362
513,parsEofInHashIf,"End of file in #if section begun at or after here"
363363
514,parsEofInString,"End of file in string begun at or before here"
364364
515,parsEofInVerbatimString,"End of file in verbatim string begun at or before here"
@@ -374,14 +374,14 @@ csSeeAvailableOverloads,"The available overloads are shown below (or in the Erro
374374
526,parsOnlyOneWithAugmentationAllowed,"At most one 'with' augmentation is permitted"
375375
527,parsUnexpectedSemicolon,"A semicolon is not expected at this point"
376376
528,parsUnexpectedEndOfFile,"Unexpected end of input"
377-
529,parsUnexpectedVisibilityDeclaration,"Accessibility modifiers are not permitted here"
377+
529,parsUnexpectedVisibilityDeclaration,"Accessibility modifiers are not permitted here, but '%s' was given."
378378
530,parsOnlyHashDirectivesAllowed,"Only '#' compiler directives may occur prior to the first 'namespace' declaration"
379379
531,parsVisibilityDeclarationsShouldComePriorToIdentifier,"Accessibility modifiers should come immediately prior to the identifier naming a construct"
380380
532,parsNamespaceOrModuleNotBoth,"Files should begin with either a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule', but not both. To define a module within a namespace use 'module SomeModule = ...'"
381381
534,parsModuleAbbreviationMustBeSimpleName,"A module abbreviation must be a simple name, not a path"
382382
535,parsIgnoreAttributesOnModuleAbbreviation,"Ignoring attributes on module abbreviation"
383-
536,parsIgnoreAttributesOnModuleAbbreviationAlwaysPrivate,"Ignoringaccessibility attribute on module abbreviation. Module abbreviations are always private."
384-
537,parsIgnoreVisibilityOnModuleAbbreviationAlwaysPrivate,"Ignoringvisibility attribute on module abbreviation. Module abbreviations are always private."
383+
536,parsIgnoreAttributesOnModuleAbbreviationAlwaysPrivate,"The '%s'accessibility attribute is not allowed on module abbreviation. Module abbreviations are always private."
384+
537,parsIgnoreVisibilityOnModuleAbbreviationAlwaysPrivate,"The '%s'visibility attribute is not allowed on module abbreviation. Module abbreviations are always private."
385385
538,parsUnClosedBlockInHashLight,"Unclosed block"
386386
539,parsUnmatchedBeginOrStruct,"Unmatched 'begin' or 'struct'"
387387
541,parsModuleDefnMustBeSimpleName,"A module name must be a simple name, not a path"

‎src/fsharp/pars.fsy‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ let mkUnderscoreRecdField m = LongIdentWithDots([ident("_", m)], []), false
5353
let mkRecdField lidwd = lidwd, true
5454

5555
let mkSynDoBinding (vis,strict,expr,m) =
56-
if Option.isSome vis then errorR(Error(FSComp.SR.parsDoCannotHaveVisibilityDeclarations(),m));
56+
match vis with
57+
| Some vis -> errorR(Error(FSComp.SR.parsDoCannotHaveVisibilityDeclarations (vis.ToString()),m))
58+
| None -> ()
5759
Binding (None,
5860
(if strict then DoBinding else StandaloneExpression),
5961
false,false,[],PreXmlDoc.Empty,SynInfo.emptySynValData,
@@ -546,7 +548,9 @@ interactiveDefns:
546548
/* An expression as part of one interaction in F# Interactive */
547549
interactiveExpr:
548550
| opt_attributes opt_declVisibility declExpr
549-
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(),rhs parseState 3))
551+
{ match $2 with
552+
| Some vis -> errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(vis.ToString()),rhs parseState 3))
553+
| _ -> ()
550554
let attrDecls = if not (isNil $1) then [ SynModuleDecl.Attributes ($1, rangeOfNonNilAttrs $1) ] else [] in
551555
attrDecls @ [ mkSynDoDecl($3)] }
552556

@@ -732,8 +736,9 @@ moduleSpfn:
732736
if isRec then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsInvalidUseOfRec())
733737
if List.length path <> 1 then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsModuleAbbreviationMustBeSimpleName())
734738
if List.length $1 <> 0 then raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreAttributesOnModuleAbbreviation())
735-
if Option.isSome vis then raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreVisibilityOnModuleAbbreviationAlwaysPrivate())
736-
SynModuleSigDecl.ModuleAbbrev(List.head path,$5,rhs2 parseState 3 5) }
739+
match vis with
740+
| Some vis -> raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreVisibilityOnModuleAbbreviationAlwaysPrivate(vis.ToString()))
741+
| _ -> SynModuleSigDecl.ModuleAbbrev(List.head path,$5,rhs2 parseState 3 5) }
737742

738743
| opt_attributes opt_declVisibility moduleIntro colonOrEquals moduleSpecBlock
739744
{ let isRec, path, xml, vis = $3
@@ -1131,17 +1136,23 @@ moduleDefnsOrExprPossiblyEmpty:
11311136
/* A naked expression is only allowed at the start of a module/file, or straight after a topSeparators */
11321137
moduleDefnsOrExpr:
11331138
| opt_attributes opt_declVisibility declExpr topSeparators moduleDefnsOrExpr
1134-
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(),rhs parseState 3))
1139+
{ match $2 with
1140+
| Some vis -> errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(vis.ToString()),rhs parseState 3))
1141+
| _ -> ()
11351142
let attrDecls = if not (isNil $1) then [ SynModuleDecl.Attributes ($1, rangeOfNonNilAttrs $1) ] else []
11361143
attrDecls @ mkSynDoDecl ($3) :: $5 }
11371144

11381145
| opt_attributes opt_declVisibility declExpr topSeparators
1139-
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(),rhs parseState 3))
1146+
{ match $2 with
1147+
| Some vis -> errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(vis.ToString()),rhs parseState 3))
1148+
| _ -> ()
11401149
let attrDecls = if not (isNil $1) then [ SynModuleDecl.Attributes ($1, rangeOfNonNilAttrs $1) ] else []
11411150
attrDecls @ [ mkSynDoDecl($3) ] }
11421151

11431152
| opt_attributes opt_declVisibility declExpr
1144-
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(),rhs parseState 3))
1153+
{ match $2 with
1154+
| Some vis -> errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(vis.ToString()),rhs parseState 3))
1155+
| _ -> ()
11451156
let attrDecls = if not (isNil $1) then [ SynModuleDecl.Attributes ($1, rangeOfNonNilAttrs $1) ] else []
11461157
attrDecls @ [ mkSynDoDecl($3) ] }
11471158

@@ -1229,7 +1240,9 @@ moduleDefn:
12291240
if isRec then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsInvalidUseOfRec())
12301241
if List.length path <> 1 then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsModuleAbbreviationMustBeSimpleName())
12311242
if List.length $1 <> 0 then raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreAttributesOnModuleAbbreviation())
1232-
if Option.isSome vis then raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreAttributesOnModuleAbbreviationAlwaysPrivate())
1243+
match vis with
1244+
| Some vis -> raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreAttributesOnModuleAbbreviationAlwaysPrivate(vis.ToString()))
1245+
| _ -> ()
12331246
[ SynModuleDecl.ModuleAbbrev(List.head path,eqn,(rhs parseState 3, eqn) ||> unionRangeWithListBy (fun id -> id.idRange) ) ]
12341247
| Choice2Of2 def ->
12351248
if List.length path <> 1 then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsModuleAbbreviationMustBeSimpleName())
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// #Warnings
2+
//<Expects status="Error" id="FS0531">Accessibility</Expects>
3+
//<Expects status="Error" id="FS0512">Accessibility modifiers are not permitted on 'do' bindings, but 'Private' was given.</Expects>
4+
5+
typeX()=
6+
do()
7+
privatedo()
8+
static memberY()=1
9+
10+
11+
exit0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// #Warnings
2+
//<Expects status="Error" id="FS0536">The 'Public' accessibility attribute is not allowed on module abbreviation.</Expects>
3+
4+
modulepublicL1= List
5+
6+
exit0

‎tests/fsharpqa/Source/Warnings/env.lst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@
7272
SOURCE=WarnIfImplicitlyDiscarded.fs
7373
SOURCE=WarnOnlyOnLastExpression.fs
7474
SOURCE=WarnIfPossiblePropertySetter.fs
75+
SOURCE=DoCannotHaveVisibilityDeclarations.fs
76+
SOURCE=ModuleAbbreviationsArePrivate.fs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp