Added some permission checks
This commit is contained in:
parent
ae50fab159
commit
b8693af68b
@ -249,6 +249,19 @@ func (analyzer *analysisOperation) typeCheck (
|
||||
return
|
||||
}
|
||||
|
||||
// inCurrentModule returns whether or not the specified section resides within
|
||||
// the current module.
|
||||
func (analyzer *analysisOperation) inCurrentModule (
|
||||
section Section,
|
||||
) (
|
||||
inCurrent bool,
|
||||
){
|
||||
inCurrent =
|
||||
section.locator().modulePath ==
|
||||
analyzer.currentPosition.modulePath
|
||||
return
|
||||
}
|
||||
|
||||
// doIndent perfroms a fmt.Sprint operation on input, indenting the string. This
|
||||
// does not add a trailing newline.
|
||||
func doIndent (indent int, input ...any) (output string) {
|
||||
|
@ -169,6 +169,8 @@ func (analyzer *analysisOperation) analyzeObjectMembers (
|
||||
err error,
|
||||
) {
|
||||
inheritedSection := into.what.actual
|
||||
inheritsFromSameModule := analyzer.inCurrentModule(inheritedSection)
|
||||
|
||||
for index := 0; index < from.MembersLength(); index ++ {
|
||||
inputMember := from.Member(index)
|
||||
|
||||
@ -185,6 +187,20 @@ func (analyzer *analysisOperation) analyzeObjectMembers (
|
||||
// modifying default value/permissions of an
|
||||
// inherited member
|
||||
|
||||
canAccessMember :=
|
||||
inheritsFromSameModule ||
|
||||
inheritedMember.permission !=
|
||||
types.PermissionPrivate
|
||||
|
||||
if !canAccessMember {
|
||||
err = inputMember.NewError (
|
||||
"inherited member is private (pv) in " +
|
||||
"parent type, and cannot be modified " +
|
||||
"here",
|
||||
infoerr.ErrorKindError)
|
||||
return
|
||||
}
|
||||
|
||||
outputMember.what = inheritedMember.what
|
||||
if !inputMember.Type().Nil() {
|
||||
err = inputMember.NewError (
|
||||
@ -202,11 +218,25 @@ func (analyzer *analysisOperation) analyzeObjectMembers (
|
||||
return
|
||||
}
|
||||
|
||||
canOverwriteMember :=
|
||||
inheritsFromSameModule ||
|
||||
inheritedMember.permission ==
|
||||
types.PermissionReadWrite
|
||||
|
||||
// apply default value
|
||||
if inputMember.Argument().Nil() {
|
||||
// if it is unspecified, inherit it
|
||||
outputMember.argument = inheritedMember.argument
|
||||
} else {
|
||||
if !canOverwriteMember {
|
||||
err = inputMember.Argument().NewError (
|
||||
"member is read-only (ro) in " +
|
||||
"parent type, its default " +
|
||||
"value cannot be overridden",
|
||||
infoerr.ErrorKindError)
|
||||
return
|
||||
}
|
||||
|
||||
outputMember.argument,
|
||||
err = analyzer.analyzeArgument(inputMember.Argument())
|
||||
if err != nil { return }
|
||||
|
@ -10,7 +10,11 @@ type ro cBasicObject:Obj
|
||||
ro that:UInt
|
||||
ro this:Int
|
||||
|
||||
type ro dInheritedFromOther:something.Thing
|
||||
type ro dInheritFromOther:something.aBasic
|
||||
|
||||
type ro eInheritObject:cBasicObject
|
||||
rw that
|
||||
ro that 5
|
||||
|
||||
type ro dInheritObjectFromOther:something.bBird
|
||||
ro wing 2
|
||||
ro beak:Int 238
|
||||
|
@ -1,3 +1,6 @@
|
||||
:arf
|
||||
---
|
||||
type ro Thing:Int
|
||||
type ro aBasic:Int
|
||||
|
||||
type ro bBird:Obj
|
||||
rw wing:Int 2
|
||||
|
Reference in New Issue
Block a user