Pass TestUnitPrivateMethod Err

This commit is contained in:
Sasha Koshka 2024-02-16 12:48:25 -05:00
parent d2cb1f78c4
commit 95db63b1b8
3 changed files with 73 additions and 2 deletions

View File

@ -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:

View File

@ -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 }

View File

@ -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`,
)}