Преглед изворни кода

Prevent assignment of weaker access privileges.

woollybah пре 8 година
родитељ
комит
b15b248585
1 измењених фајлова са 26 додато и 0 уклоњено
  1. 26 0
      decl.bmx

+ 26 - 0
decl.bmx

@@ -148,6 +148,10 @@ Type TDecl
 		Return (attrs & DECL_PROTECTED)<>0
 	End Method
 	
+	Method IsPublic:Int()
+		Return Not (IsPrivate() Or IsProtected())
+	End Method
+	
 	Method IsAbstract:Int()
 		Return (attrs & DECL_ABSTRACT)<>0
 	End Method
@@ -1779,6 +1783,28 @@ Type TFuncDecl Extends TBlockDecl
 
 						If EqualsFunc( decl ) And Not voidReturnTypeFail
 
+							' check we aren't attempting to assign weaker access modifiers
+							If (IsProtected() And decl.IsPublic()) Or (IsPrivate() And (decl.IsProtected() Or decl.IsPublic())) Then
+							
+								Local p:String
+								If IsProtected() Then
+									p = "Protected"
+								Else
+									p = "Private"
+								End If
+								
+								Local dp:String
+								If decl.IsPublic() Then
+									dp = "Public"
+								Else
+									dp = "Protected"
+								End If
+							
+								Err ToString() + " clashes with " + decl.ToString() + ". Attempt to assign weaker access privileges ('" + p + "'), was '" + dp + "'."
+							
+							End If
+						
+
 							If Not retType.EqualsType( decl.retType ) And retType.ExtendsType( decl.retType ) Then
 								returnTypeSubclassed = True
 							End If