Skip to content

Commit

Permalink
FIX some inference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed May 24, 2024
1 parent 7ed998c commit eeed2a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private CfgNode BuildLabel(LuaLabelStatSyntax labelStat, CfgNode sourceBlock)
{
if (!_scopeLabels.TryAdd(name, labelBlock))
{
labelStat.PushDiagnostic(DiagnosticSeverity.Error, $"Label {name} already defined");
// labelStat.PushDiagnostic(DiagnosticSeverity.Error, $"Label {name} already defined");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ public class FlowAnalyzer(LuaCompilation compilation) : LuaAnalyzer(compilation,
{
public override void Analyze(AnalyzeContext analyzeContext)
{
var cfgTuples = analyzeContext.LuaDocuments
.SelectMany(it => it.SyntaxTree.SyntaxRoot.Descendants.OfType<LuaBlockSyntax>())
// .AsParallel()
.Select(it => (it.UniqueId, new CfgBuilder().Build(it)));

foreach (var cfgTuple in cfgTuples)
foreach (var document in analyzeContext.LuaDocuments)
{
analyzeContext.ControlFlowGraphs[cfgTuple.Item1] = cfgTuple.Item2;
var syntaxTree = document.SyntaxTree;

var builder = new CfgBuilder();
var blocks = syntaxTree.SyntaxRoot.Descendants.OfType<LuaBlockSyntax>();
foreach (var block in blocks)
{
if (block.Parent is LuaSourceSyntax or LuaClosureExprSyntax)
{
analyzeContext.ControlFlowGraphs[block.UniqueId] = builder.Build(block);
}
}
}
}
}
2 changes: 1 addition & 1 deletion EmmyLua/CodeAnalysis/Compilation/Infer/SearchContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private IEnumerable<TypeOperator> GetOperators(TypeOperatorKind kind, LuaNamedTy

var declarationTree = Compilation.GetDeclarationTree(element.DocumentId);
declaration = declarationTree?.FindDeclaration(element, this);
if (Features.Cache)
if (Features.Cache && declaration is not null)
{
DeclarationCaches[element.UniqueId] = declaration;
}
Expand Down

0 comments on commit eeed2a2

Please sign in to comment.