@@ -12,6 +12,12 @@ class MemberUtilities
12
12
"__tostring" ,
13
13
} ;
14
14
15
+ private static readonly ( MemberModifierFlags a , MemberModifierFlags b , string msg ) [ ] flagConflicts =
16
+ {
17
+ ( MemberModifierFlags . Private , MemberModifierFlags . Static , "members declared static may not be private" ) ,
18
+ ( MemberModifierFlags . Public , MemberModifierFlags . Private , null )
19
+ } ;
20
+
15
21
public static void CheckReserved ( Token name , string buildKind )
16
22
{
17
23
if ( reservedFields . Contains ( name . Text ) )
@@ -25,20 +31,22 @@ public static void AddModifierFlag(ref MemberModifierFlags source, Token token)
25
31
var flag = token . ToMemberModiferFlag ( ) ;
26
32
if ( source . HasFlag ( flag ) )
27
33
{
28
- NodeBase . UnexpectedTokenType ( token ) ;
34
+ throw new SyntaxErrorException ( token , "duplicate modifier '{0}'" , token . Text ) ;
29
35
}
30
36
source |= flag ;
31
- }
32
-
33
- public static void CheckModifierCombination ( Token nameToken , MemberModifierFlags modifiers )
34
- {
35
- if ( modifiers . HasFlag ( MemberModifierFlags . Private ) &&
36
- modifiers . HasFlag ( MemberModifierFlags . Static ) )
37
- throw new SyntaxErrorException ( nameToken , "members declared static may not be private" ) ;
38
37
39
- if ( modifiers . HasFlag ( MemberModifierFlags . Private ) &&
40
- modifiers . HasFlag ( MemberModifierFlags . Public ) )
41
- throw new SyntaxErrorException ( nameToken , "conflicting access modifiers public and private" ) ;
38
+ foreach ( var combo in flagConflicts )
39
+ {
40
+ if ( source . HasFlag ( combo . a ) && source . HasFlag ( combo . b ) )
41
+ {
42
+ if ( combo . msg != null )
43
+ throw new SyntaxErrorException ( token , combo . msg ) ;
44
+ throw new SyntaxErrorException ( token ,
45
+ "conflicting modifiers '{0}' and '{1}'" ,
46
+ combo . a . ToString ( ) . ToLowerInvariant ( ) ,
47
+ combo . b . ToString ( ) . ToLowerInvariant ( ) ) ;
48
+ }
49
+ }
42
50
}
43
51
}
44
52
}
0 commit comments