Fix behavior of Tree.analyzeMethodOrBehavior()

This commit is contained in:
Sasha Koshka 2024-02-16 12:43:42 -05:00
parent 6c7c7c9d99
commit 1fea25ba91
4 changed files with 32 additions and 8 deletions

View File

@ -98,9 +98,16 @@ func (this *Tree) analyzeCall (
Name: call.Name,
})
call.Function = function
call.Unit = unit
call.Unit = function.Unit
if err != nil { return nil, err }
// check access permissions
if function.Acc == entity.AccessPrivate && function.Unit != this.unit {
return nil, errors.Errorf (
call.Position, "function %v::[%v] is private",
call.UnitNickname, call.Name)
}
// check return result
err = this.canAssign(call.Position, into, mode, function.Signature.Return)
if err != nil { return nil, err }
@ -145,13 +152,20 @@ func (this *Tree) analyzeMethodCall (
// extract signature
var signature *entity.Signature
switch method.(type) {
switch method := method.(type) {
case *entity.Signature:
signature = method.(*entity.Signature)
signature = method
call.Behavior = signature
case *entity.Method:
signature = method.(*entity.Method).Signature
call.Method = method.(*entity.Method)
signature = method.Signature
call.Method = method
// since this is a method, check access permissions
if method.Acc == entity.AccessPrivate && method.Unit != this.unit {
return nil, errors.Errorf (
method.Position, "method %v.[%v] is private",
method.TypeName, method.Signature.Name)
}
default:
panic(fmt.Sprint (
"Tree.analyzeMethodOrBehavior returned ",

View File

@ -37,6 +37,9 @@ func (this *Tree) analyzeMethod (
typeKey.Name, name)
}
// set method's unit, very important information yes
method.Unit = owner.Unit
// create a new scope context for this function
this.pushScopeContext(method)
this.pushScope(method)
@ -117,9 +120,10 @@ func (this *Tree) analyzeMethodOrBehaviorInternal (
case *entity.TypeNamed:
ty := ty.(*entity.TypeNamed)
typeKey := Key {
Unit: this.unit,
Unit: ty.Unit,
Name: ty.Name,
}
println(typeKey.String())
if this.methodExists(this.methodKey(typeKey, name)) {
method, err := this.analyzeMethod(pos, typeKey, name)
if err != nil { return nil, err }

View File

@ -90,11 +90,16 @@ func (this *Tree) analyzeTypeInternal (
case *entity.TypeNamed:
ty := ty.(*entity.TypeNamed)
updateIncompleteInfo()
// resolve nickname of the unit where the typedef is
if primitive, isPrimitive := primitiveTypes[ty.Name]; isPrimitive {
return primitive, nil
}
unit, err := this.resolveNickname(ty.Position, ty.UnitNickname)
if err != nil { return nil, err }
ty.Unit = unit
// analyze the typedef
def, err := this.analyzeTypedef(ty.Position, Key {
Unit: unit,
Name: ty.Name,

View File

@ -105,9 +105,10 @@ type Method struct {
Body Expression
// Semantics
Scope
Unit uuid.UUID
Type Type
This *Declaration
Scope
}
func (*Method) topLevel(){}
func (this *Method) String () string {