Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/Neo.Compiler.CSharp/CompilationEngine/CompilationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private List<CompilationContext> CompileProjectContracts(Compilation compilation
var classDependencies = new Dictionary<INamedTypeSymbol, List<INamedTypeSymbol>>(SymbolEqualityComparer.Default);
var allSmartContracts = new HashSet<INamedTypeSymbol>(SymbolEqualityComparer.Default);
var allClassSymbols = new List<INamedTypeSymbol?>();
var classSymbols = new List<INamedTypeSymbol>();
foreach (var tree in compilation.SyntaxTrees)
{
var semanticModel = compilation.GetSemanticModel(tree);
Expand All @@ -298,22 +299,37 @@ private List<CompilationContext> CompileProjectContracts(Compilation compilation
{
var classSymbol = semanticModel.GetDeclaredSymbol(classNode);
allClassSymbols.Add(classSymbol);
if (classSymbol is null) continue;

classSymbols.Add(classSymbol);
if (classSymbol is { IsAbstract: false, DeclaredAccessibility: Accessibility.Public } && IsDerivedFromSmartContract(classSymbol))
{
allSmartContracts.Add(classSymbol);
classDependencies[classSymbol] = [];
foreach (var member in classSymbol.GetMembers())
{
var memberTypeSymbol = (member as IFieldSymbol)?.Type ?? (member as IPropertySymbol)?.Type;
if (memberTypeSymbol is INamedTypeSymbol namedTypeSymbol && allSmartContracts.Contains(namedTypeSymbol) && !namedTypeSymbol.IsAbstract)
{
classDependencies[classSymbol].Add(namedTypeSymbol);
}
}
}
}
}

foreach (var classSymbol in classSymbols)
{
if (!allSmartContracts.Contains(classSymbol))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check if it's abstract here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @Jim8y

continue;

foreach (var member in classSymbol.GetMembers())
{
var memberTypeSymbol = (member as IFieldSymbol)?.Type ?? (member as IPropertySymbol)?.Type;
if (memberTypeSymbol is not INamedTypeSymbol namedTypeSymbol)
continue;
if (namedTypeSymbol.IsAbstract)
continue;
if (!allSmartContracts.Contains(namedTypeSymbol))
continue;
if (classDependencies[classSymbol].Any(p => SymbolEqualityComparer.Default.Equals(p, namedTypeSymbol)))
continue;
classDependencies[classSymbol].Add(namedTypeSymbol);
}
}

// Verify if there is any valid smart contract class
if (classDependencies.Count == 0) throw new FormatException("No valid neo SmartContract found. Please make sure your contract is subclass of SmartContract and is not abstract.");
// Check contract dependencies, make sure there is no cycle in the dependency graph
Expand Down
Loading