diff --git a/analyzer/expression.go b/analyzer/expression.go index 83faded..5d71174 100644 --- a/analyzer/expression.go +++ b/analyzer/expression.go @@ -163,7 +163,7 @@ func (this *Tree) analyzeMethodCall ( // 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", + call.Position, "method %v.[%v] is private", method.TypeName, method.Signature.Name) } default: diff --git a/analyzer/method.go b/analyzer/method.go index 74de068..fa3ec83 100644 --- a/analyzer/method.go +++ b/analyzer/method.go @@ -123,7 +123,6 @@ func (this *Tree) analyzeMethodOrBehaviorInternal ( 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 } diff --git a/analyzer/multiunit_test.go b/analyzer/multiunit_test.go new file mode 100644 index 0000000..ea12a0d --- /dev/null +++ b/analyzer/multiunit_test.go @@ -0,0 +1,72 @@ +package analyzer + +import "testing" + +func TestTwoUnit (test *testing.T) { +testUnits (test, +`[main]:something::X = 5`, + +"something.fspl", +`+ X:Int`, +)} + +func TestUnitPrivateTypeErr (test *testing.T) { +testUnitsErr (test, +"main.fspl", "type other::X is private", 1, 8, +`[main]:other::X = 5`, + +"other.fspl", +`- X:Int`, +)} + +func TestUnitPrivateFunctionErr (test *testing.T) { +testUnitsErr (test, +"main.fspl", "function other::[x] is private", 1, 11, +`[y]:Int = other::[x]`, + +"other.fspl", +`- [x]:Int = 5`, +)} + +func TestUnitPrivateMethodErr (test *testing.T) { +testUnitsErr (test, +"main.fspl", "method T.[x] is private", 1, 21, +`[y]:Int = z:other::T.[x]`, + +"other.fspl", +` ++ T:Int +- T.[x]:Int = 5`, +)} + +func TestUnitAssignLiteralRestrictedErr (test *testing.T) { +testUnitsErr (test, +"main.fspl", "type RestrictedInt is restricted", 0, 0, +`[main]:other::RestrictedInt = 5`, + +"other.fspl", +`~ RestrictedInt:Int`, +)} + +func TestUnitMemberAccessRestrictedErr (test *testing.T) { +testUnitsErr (test, +"main.fspl", "type RestrictedStruct is restricted", 0, 0, +`[main] = { + x:other::RestrictedStruct + x.x = 5 +}`, + +"other.fspl", +`~ RestrictedStruct:(. x:Int y:Int)`, +)} + +func TestNestedUnitTypedef (test *testing.T) { +testUnits (test, +`[main]:layer1::X = 5`, + +"layer0.fspl", +`+ X:Int`, + +"layer1.fspl", +`+ X:layer0::X`, +)}