Skip to content

fix: function param shadowing and nested inline call arg resolution#46

Merged
someone235 merged 3 commits intokaspanet:masterfrom
Manyfestation:compiler-bug-fixes
Mar 5, 2026
Merged

fix: function param shadowing and nested inline call arg resolution#46
someone235 merged 3 commits intokaspanet:masterfrom
Manyfestation:compiler-bug-fixes

Conversation

@Manyfestation
Copy link
Collaborator

  • Remove constructor/constant names from env when they collide with function param names (prioritizing function parameters).
  • Copy caller's _arg bindings and params into inline call env, allowing nested synthetic argument chains.
  • pub const SYNTHETIC_ARG_PREFIX.
  • Add regression tests for both fixes.

- Remove constructor/constant names from env when they collide with
  function param names (prioritizing function parameters).
- Propagate caller's __arg_ bindings and params map into inline calls,
  allowing nested synthetic argument chains to resolve correctly.
- Extract magic string into pub const SYNTHETIC_ARG_PREFIX.
- Add regression tests for both fixes.
use crate::span;

/// Prefix used for synthetic argument bindings during inline function expansion.
pub const SYNTHETIC_ARG_PREFIX: &str = "__arg_";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think prefix shouldn't contains _ tail

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The prefix itself did not change,
image
Just moved into a const

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I saw, but I don't see why we shouldn't only consider __args instead of __args_ in synthetic checks.

Unless we envision to use qualification such as __args_${scope} in the future?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @IzioDev

Comment on lines +3565 to +3569
// When a constructor constant and a function parameter share the same name,
// the function parameter value must be used (not the constant).
let source = r#"
contract Shadow(int fee) {
entrypoint function main(int fee) {
Copy link
Collaborator

@IzioDev IzioDev Mar 5, 2026

Choose a reason for hiding this comment

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

Shouldn't this even be disallowed to reduce confusion?
Scope precedence is unclear

Bonus: how should contract-level state be treated as-well

Copy link
Contributor

Choose a reason for hiding this comment

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

This is very common in most modern programming languages.

Comment on lines +3565 to +3569
// When a constructor constant and a function parameter share the same name,
// the function parameter value must be used (not the constant).
let source = r#"
contract Shadow(int fee) {
entrypoint function main(int fee) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very common in most modern programming languages.

// inner calls can resolve arguments that flow through outer calls.
let source = r#"
contract NestedArgs() {
function inner(int x) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add another level? To see the fix didn't push the bug one level further

use crate::span;

/// Prefix used for synthetic argument bindings during inline function expansion.
pub const SYNTHETIC_ARG_PREFIX: &str = "__arg_";
Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @IzioDev


let mut yields: Vec<Expr<'i>> = Vec::new();
let params = HashMap::new();
let params = caller_params.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just rename caller_params -> params and remove this line

@someone235 someone235 mentioned this pull request Mar 5, 2026
@someone235 someone235 merged commit 2836a52 into kaspanet:master Mar 5, 2026
4 checks passed
Manyfestation added a commit to Manyfestation/silverscript that referenced this pull request Mar 5, 2026
someone235 pushed a commit that referenced this pull request Mar 5, 2026
* Add debugger infrastructure + CLI debugger

* fmt

* Fix clippy warning and apply debugger lint fixes

* Restore state transition support on debugger branch

* Fix AST JSON fixtures for current type_name schema

* Fix length stack cleanup and remove unused target deps

* Restore typed return TypeRef model

* Minimize debugger branch against upstream master

* Refactor sil-debug CLI to clap and use faster-hex

* Fix inline call param resolution and improve debug event tracking

* Finalize debugger inline resolution and cleanup

* Fix param shadowing over constructor constants

* Refine debugger recorder flow and simplify compiler call sites

* Fix debugger stack bindings and opcode cursor sync

* Clarify debugger sequence and stepping documentation

* Simplify inline resolution and debugger variable plumbing

* CompileCtx

* Restore pre-refactor staged debugger snapshot

* Minimize compiler footprint by dropping CompileCtx refactor

* Deduplicate expression recursion in resolve and inline arg expansion

* Simplify inline call flow and remove synthetic arg helpers

* Fix inline call bug

* Fix clippy redundant pattern matching in debug session test

* Rename changes

* feat(debugger): port debugger onto izio spanned-ast core

* fmt

* debugger: fix tx-context local eval and loop index visibility

* refactor: split debugger into separate crates

- Rename debug.rs → debug_info.rs in silverscript-lang (types-only module)
- Create debugger-session library crate (session runtime, presentation)
- Create cli-debugger binary crate (renamed from sil-debug)
- Migrate debug session tests and CLI smoke test to new crates
- Update all imports across workspace

* enhance expression resolution

* Final touches , readme, tests

* fmt

* Fix compiler compatibility after merging origin/master

* fix: align with upstream PR #44 — restore serialize_i64 encoding

Bad merge resolution had reverted PR #44 changes:
- Restore serialize_i64 instead of to_le_bytes+OpBin2Num for int fields
- Restore Ok(9) field chunk size (was incorrectly Ok(10))
- Remove spurious OpBin2Num injection in validate_output_state
- Update test expectations to match corrected encoding

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* PR cleanup - remove redundent logic & structs

* Simplify fn recorder

* More docs, and better namings

* fix: function param shadowing and nested inline call arg resolution

- Remove constructor/constant names from env when they collide with
  function param names (prioritizing function parameters).
- Propagate caller's __arg_ bindings and params map into inline calls,
  allowing nested synthetic argument chains to resolve correctly.
- Extract magic string into pub const SYNTHETIC_ARG_PREFIX.
- Add regression tests for both fixes.

* Refactor debug recorder to unify entrypoint and contract recorders

* Enhance session module with failure reporting and call stack management

* sync: align debugger with merged #46 and resolve merge artifacts

* rename caller_params to params

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.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.

3 participants