Track table definition location

This commit is contained in:
JohnnyMorganz 2023-01-11 15:53:34 +00:00
parent be52bd91e4
commit 306db6fb59
3 changed files with 6 additions and 0 deletions

View file

@ -375,6 +375,7 @@ struct TableType
std::vector<TypeId> instantiatedTypeParams; std::vector<TypeId> instantiatedTypeParams;
std::vector<TypePackId> instantiatedTypePackParams; std::vector<TypePackId> instantiatedTypePackParams;
ModuleName definitionModuleName; ModuleName definitionModuleName;
Location definitionLocation;
std::optional<TypeId> boundTo; std::optional<TypeId> boundTo;
Tags tags; Tags tags;

View file

@ -116,6 +116,7 @@ TypeId ReplaceGenerics::clean(TypeId ty)
{ {
TableType clone = TableType{ttv->props, ttv->indexer, level, scope, TableState::Free}; TableType clone = TableType{ttv->props, ttv->indexer, level, scope, TableState::Free};
clone.definitionModuleName = ttv->definitionModuleName; clone.definitionModuleName = ttv->definitionModuleName;
clone.definitionLocation = ttv->definitionLocation;
return addType(std::move(clone)); return addType(std::move(clone));
} }
else else

View file

@ -1535,6 +1535,7 @@ void TypeChecker::check(const ScopePtr& scope, const AstStatTypeAlias& typealias
// This is a shallow clone, original recursive links to self are not updated // This is a shallow clone, original recursive links to self are not updated
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, ttv->state}; TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, ttv->state};
clone.definitionModuleName = ttv->definitionModuleName; clone.definitionModuleName = ttv->definitionModuleName;
clone.definitionLocation = ttv->definitionLocation;
clone.name = name; clone.name = name;
for (auto param : binding->typeParams) for (auto param : binding->typeParams)
@ -2370,6 +2371,7 @@ TypeId TypeChecker::checkExprTable(
TableState state = TableState::Unsealed; TableState state = TableState::Unsealed;
TableType table = TableType{std::move(props), indexer, scope->level, state}; TableType table = TableType{std::move(props), indexer, scope->level, state};
table.definitionModuleName = currentModuleName; table.definitionModuleName = currentModuleName;
table.definitionLocation = expr.location;
return addType(table); return addType(table);
} }
@ -5371,6 +5373,7 @@ TypeId TypeChecker::resolveTypeWorker(const ScopePtr& scope, const AstType& anno
TableType ttv{props, tableIndexer, scope->level, TableState::Sealed}; TableType ttv{props, tableIndexer, scope->level, TableState::Sealed};
ttv.definitionModuleName = currentModuleName; ttv.definitionModuleName = currentModuleName;
ttv.definitionLocation = annotation.location;
return addType(std::move(ttv)); return addType(std::move(ttv));
} }
else if (const auto& func = annotation.as<AstTypeFunction>()) else if (const auto& func = annotation.as<AstTypeFunction>())
@ -5572,6 +5575,7 @@ TypeId TypeChecker::instantiateTypeFun(const ScopePtr& scope, const TypeFun& tf,
ttv->instantiatedTypeParams = typeParams; ttv->instantiatedTypeParams = typeParams;
ttv->instantiatedTypePackParams = typePackParams; ttv->instantiatedTypePackParams = typePackParams;
ttv->definitionModuleName = currentModuleName; ttv->definitionModuleName = currentModuleName;
ttv->definitionLocation = location;
} }
return instantiated; return instantiated;