Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cancel unnecessary constructors #1185

Merged
merged 4 commits into from
Oct 4, 2024

Conversation

Hecate2
Copy link
Contributor

@Hecate2 Hecate2 commented Sep 30, 2024

TODO in the future: regex may not be reliable enough

@Hecate2 Hecate2 changed the title cancel constructors cancel unnecessary constructors Sep 30, 2024
…to cancel-constructor

# Conflicts:
#	tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_Attribute.cs
#	tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_ManifestAttribute.cs
#	tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_SupportedStandard26.cs
#	tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_SupportedStandard27.cs
@Jim8y Jim8y requested a review from shargon October 2, 2024 17:43
@@ -34,7 +34,7 @@ public class CompilationEngine(CompilationOptions options)
internal CompilationOptions Options { get; private set; } = options;
private static readonly MetadataReference[] CommonReferences;
private static readonly Dictionary<string, MetadataReference> MetaReferences = [];
private static readonly Regex s_pattern = new(@"^(Neo\.SmartContract\.Framework\.SmartContract|SmartContract\.Framework\.SmartContract|Framework\.SmartContract|SmartContract)$");
internal static readonly Regex s_pattern = new(@"^(Neo\.SmartContract\.Framework\.SmartContract|SmartContract\.Framework\.SmartContract|Framework\.SmartContract|SmartContract|Neo\.SmartContract\.Framework\.Nep17Token|Neo\.SmartContract\.Framework\.TokenContract|Neo.SmartContract.Framework.Nep11Token<.*>)$");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should try to remove this regex

Copy link
Member

Choose a reason for hiding this comment

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

@Hecate2 this is needed? it should check the hierarchy

Copy link
Member

Choose a reason for hiding this comment

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

  static bool IsDerivedFromSmartContract(INamedTypeSymbol classSymbol, Regex pattern)
  {
      var baseType = classSymbol.BaseType;
      while (baseType != null)
      {
          if (pattern.IsMatch(baseType.ToString() ?? string.Empty))
          {
              return true;
          }
          baseType = baseType.BaseType;
      }
      return false;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IsDerivedFromSmartContract returns true even when a asmart contract is derived for many times. e.g.
class A: SmartContract
class B: A
class C: B
IsDerivedFromSmartContract returns true for B and C. But in B and C we may call base, or utilize the constructor of A.

@shargon shargon merged commit bb13c53 into neo-project:master Oct 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants