Skip to content

fix: handle partial class compilation with correct SemanticModel#1488

Merged
Jim8y merged 3 commits intomaster-n3from
fix/partial-class-compilation
Jan 28, 2026
Merged

fix: handle partial class compilation with correct SemanticModel#1488
Jim8y merged 3 commits intomaster-n3from
fix/partial-class-compilation

Conversation

@Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Jan 27, 2026

Fix NC5001 compiler errors when compiling contracts with partial classes (e.g., Example.SmartContract.NFT).

Changes

  • Add SemanticModelExtensions.GetModelForNode() helper
  • Fix Expression.cs, InvocationExpression.cs, SourceConvert.cs

Closes #1363

@vncoelho
Copy link
Member

I will test asap

@shargon
Copy link
Member

shargon commented Jan 27, 2026

Sometimes master, Sometimes master-n3 🫣

@Jim8y
Copy link
Contributor Author

Jim8y commented Jan 27, 2026

Sometimes master, Sometimes master-n3 🫣

Sigh,,,,, well....

Jim8y added 2 commits January 27, 2026 23:43
- Add SemanticModelExtensions.GetModelForNode() helper method
- Fix Expression.cs to check syntax tree before GetConstantValue
- Fix InvocationExpression.cs to get correct model for GetSymbolInfo
- Fix SourceConvert.cs to get correct model for GetTypeInfo

This fixes NC5001 errors when compiling contracts with partial classes
(e.g., Example.SmartContract.NFT) where syntax nodes may come from
different syntax trees than the current semantic model.

Closes #1363
Tests the fix for issue #1363 where syntax nodes from different
syntax trees caused NC5001 errors during compilation.

New tests cover:
- Cross-file method invocations in partial classes
- Expression-bodied members using constants from other files
- Complex expressions using both constants and methods across files
@Jim8y Jim8y force-pushed the fix/partial-class-compilation branch from 964372b to a015cbe Compare January 27, 2026 15:43
@Jim8y Jim8y changed the base branch from master to master-n3 January 27, 2026 16:36
Comment on lines +35 to +38
if (!model.SyntaxTree.Equals(expression.SyntaxTree))
{
model = model.Compilation.GetSemanticModel(expression.SyntaxTree);
}
Copy link
Member

Choose a reason for hiding this comment

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

Use GetModelForNode here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestion, applied.

Apply review suggestion to use the GetModelForNode extension method
instead of inline syntax tree check. This allows constant evaluation
to work across partial class files.
@Jim8y Jim8y merged commit 715a4d4 into master-n3 Jan 28, 2026
3 checks passed
@Jim8y Jim8y deleted the fix/partial-class-compilation branch January 28, 2026 03:16
Jim8y added a commit that referenced this pull request Jan 28, 2026
* Update neo submodule to master-n3 (#1453)

Co-authored-by: Neo Dev Bot <dev@neo.local>

* Use stable framework package in templates (#1456)

* Add: FindOptions.Backwards definition (#1458)

* Add: IsContract for ContractManagement (#1454) (#1455)

Co-authored-by: Will <201105916+Wi1l-B0t@users.noreply.github.com>

* CI: run on master-n3 (#1459)

* Update neo (#1463)

* Upgrade devpack to Neo v3.9.0 (#1464)

* Upgrade devpack to Neo v3.9.0

* Restore manifest version in test artifacts

* Add: comment doc for Framework.Services (#1460) (#1467)

* Fix: remove many compiler warnings (#1461) (#1469)

* Reorder (#1472)

* Fix CS0067 warning in artifacts (#1474)

* Avoid CS0067 in artifacts

* one more

* Add: comments doc for ContractMethod CallFlags (#1479)

* Add reference (#1476)

* docs: Clarify Base58CheckDecode FAULT behavior in UInt160.Parse (#1483)

Update documentation to warn that invalid Base58Check addresses will cause
execution to FAULT (abort) rather than throw a catchable exception.

Fixes #1443

* fix: HexStringInterpreter regex should only accept hex characters (#1484)

Change regex from [a-zA-Z0-9_] to [a-fA-F0-9] to properly validate
hexadecimal strings (0-9, a-f, A-F only).

Fixes #1264

* docs: Add optimizer documentation (#1481)

* docs: Add optimizer documentation

Document the bytecode optimization strategies including:
- Peephole optimization
- Jump compression
- Reachability analysis
- Miscellaneous optimizations

Also includes architecture overview and usage instructions.

* docs: add OptimizationType enum options to optimizer documentation

* fix(compiler): extend division overflow check and improve temp file security (#1485)

* fix(compiler): extend division overflow check to IntPtr type

- Add comprehensive documentation for CheckDivideOverflow method
- Extend overflow check to include IntPtr (nint) type
- Use BigInteger for consistent handling of min values
- Add clear comments explaining which types need/don't need overflow checks

Fixes HIGH-002 from security audit

* test: add unit tests for division overflow fix

Demonstrates the IntPtr (nint) division overflow issue and fix:
- Before fix: nint.MinValue / -1 would silently overflow
- After fix: properly throws in checked context

Tests cover Int32, Int64, IntPtr, and BigInteger division scenarios.

* fix: remove unsupported nint/nuint types from tests

Neo compiler does not support nint/nuint (IntPtr/UIntPtr) types.
Removed IntPtr handling from division overflow check and tests.

* test: add testing artifacts for division overflow and shift contracts

- Add Contract_DivisionOverflow.cs testing artifact
- Update Contract_shift.cs with new shift methods

All 938 tests pass locally.

* chore: revert neo submodule to master-n3 version

* fix: Support Event?.Invoke() conditional invocation pattern (#1482)

Add support for invoking events using the null-conditional operator.
When calling Event?.Invoke(...), the compiler now correctly recognizes
this as an event invocation and emits the appropriate System.Runtime.Notify call.

Fixes #1093

* Update examples for Neo v3.9 (#1465)

* Update examples for v3.9

* chore: Remove example nef and manifest artifacts

Remove compiled artifacts from examples as requested in PR review.
These files should be generated during build, not committed.

* refactor: replace neo submodule with NuGet package references (Neo 3.9.1) (#1489)

* refactor: replace neo submodule with NuGet package references (Neo 3.9.1)

- Remove neo submodule dependency
- Update project references to use NuGet packages:
  - Neo 3.9.1
  - Neo.Extensions 3.9.1
  - Neo.IO 3.9.1
  - Neo.Json 3.9.1
- Simplify CI workflow by removing submodule-related version extraction
- Fix PublishPackage job that was failing due to empty VERSION_NEO variable

* fix: workflow should support both master and master-n3 branches

* fix: restore Release job in workflow

* fix: remove neo submodule projects from solution file

* fix: handle partial class compilation with correct SemanticModel (#1488)

* fix: handle partial class compilation with correct SemanticModel

- Add SemanticModelExtensions.GetModelForNode() helper method
- Fix Expression.cs to check syntax tree before GetConstantValue
- Fix InvocationExpression.cs to get correct model for GetSymbolInfo
- Fix SourceConvert.cs to get correct model for GetTypeInfo

This fixes NC5001 errors when compiling contracts with partial classes
(e.g., Example.SmartContract.NFT) where syntax nodes may come from
different syntax trees than the current semantic model.

Closes #1363

* test: add unit tests for partial class cross-file compilation

Tests the fix for issue #1363 where syntax nodes from different
syntax trees caused NC5001 errors during compilation.

New tests cover:
- Cross-file method invocations in partial classes
- Expression-bodied members using constants from other files
- Complex expressions using both constants and methods across files

* refactor: use GetModelForNode helper in TryConvertConstant

Apply review suggestion to use the GetModelForNode extension method
instead of inline syntax tree check. This allows constant evaluation
to work across partial class files.

---------

Co-authored-by: Jimmy <jimmy@r3e.network>
Co-authored-by: Neo Dev Bot <dev@neo.local>
Co-authored-by: Will <201105916+Wi1l-B0t@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NFT example building error

4 participants