Fix index type intersections with x["prop"] syntax

This commit is contained in:
JohnnyMorganz 2023-07-03 15:26:42 +01:00
parent 118f6ed3c6
commit 1260ca5969

View file

@ -3412,6 +3412,20 @@ TypeId TypeChecker::checkLValueBinding(const ScopePtr& scope, const AstExprIndex
return prop->type();
}
}
else if (get<IntersectionType>(exprType))
{
Name name = std::string(value->value.data, value->value.size);
if (std::optional<TypeId> ty = getIndexTypeFromType(scope, exprType, name, expr.location, /* addErrors= */ false))
return *ty;
// If intersection has a table part, report that it cannot be extended just as a sealed table
if (isTableIntersection(exprType))
{
reportError(TypeError{expr.location, CannotExtendTable{exprType, CannotExtendTable::Property, name}});
return errorRecoveryType(scope);
}
}
}
else
{