[Linter] Fix super index type and handle "object or string" indexing correctly.

This commit is contained in:
Stanisław Barzowski 2021-06-06 21:06:59 +02:00
parent 12bd29d164
commit 46d1fceb9c
8 changed files with 17 additions and 3 deletions

View File

@ -234,7 +234,7 @@ func calcTP(node ast.Node, varAt map[ast.Node]*common.Variable, g *typeGraph) ty
// no recursion yet
return tpRef(anyObjectType)
case *ast.SuperIndex:
return tpRef(anyObjectType)
return tpRef(anyType)
case *ast.InSuper:
return tpRef(boolType)
case *ast.Function:

View File

@ -55,8 +55,8 @@ func check(node ast.Node, typeOf exprTypes, ec *common.ErrCollector) {
if !indexType.Number {
ec.StaticErr("Indexed value is assumed to be "+assumedType+", but index is not a number", node.Loc())
}
} else if !targetType.Array() {
// It's not an array so it must be an object
} else if !targetType.Array() && !targetType.String {
// It's not an array or a string so it must be an object
if !indexType.String {
ec.StaticErr("Indexed value is assumed to be an object, but index is not a string", node.Loc())
}

View File

@ -0,0 +1,5 @@
local foo = if true then {"foo": "bar"} else ["f", "o", "o"];
[
foo[0],
foo["foo"]
]

View File

View File

@ -0,0 +1,5 @@
local foo = if true then {"foo": "bar"} else "foo";
[
foo[0],
foo["foo"]
]

View File

@ -0,0 +1,4 @@
local foo = { config: [{ x: 'y' }] };
foo {
config: [super.config[0] { a: 'b' }],
}

View File