feat: Add validation for inline methods in Neo compiler #1385
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive validation for methods marked with
[MethodImpl(MethodImplOptions.AggressiveInlining)]
to prevent compilation issues and ensure correct behavior in Neo smart contracts.Problem
The current inline implementation in the Neo compiler lacks validation for edge cases that could lead to:
Solution
Added three key validations to the
TryProcessInlineMethods
method:1. Recursive Method Detection
CompilationException
when recursion is detected2. Ref/Out Parameter Validation
CompilationException
when ref/out parameters are found3. Method Size Warning
Changes
Modified:
src/Neo.Compiler.CSharp/MethodConvert/Helpers/ConvertHelpers.cs
IsRecursiveMethod()
helper to detect recursive callsEstimateMethodSize()
helper to estimate instruction countTryProcessInlineMethods()
Added Test Contracts:
Contract_Inline_Invalid.cs
- Test cases for invalid inline scenariosContract_Inline_EdgeCases.cs
- Comprehensive edge case testingAdded Unit Tests:
UnitTest_Inline_Validation.cs
- Validates that compilation fails for invalid casesUnitTest_Inline_EdgeCases.cs
- Tests various edge casesTesting
The PR includes comprehensive test coverage:
Impact
Checklist