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

It is not possible to define a variable with the same name as the parameter #207

Open
lum7na opened this issue Feb 10, 2025 · 2 comments
Open
Labels
C-bug Category: this is a bug

Comments

@lum7na
Copy link

lum7na commented Feb 10, 2025

I tried this code:

contract Test {
  function f(int b) private{
    uint b = 0;
  }
}

I expected to see this happen: The variable b defined inside the function body should be able to override the function parameter name, similar to the behavior in solc.

Instead, this happened: Solar threw an error message: error: identifier b already declared.

Meta

solar --version:

solar Version: 0.1.1
Commit SHA: 075267167d4cc77fdae860ed899a9114cb6f4445
Build Timestamp: 2025-02-10T08:24:35.179419652Z
Build Features: clap,version
Build Profile: release
@lum7na lum7na added the C-bug Category: this is a bug label Feb 10, 2025
@TilakMaddy
Copy link
Contributor

I think you mean "It is not possible to define a variable with the same name as the parameter"

@lum7na lum7na changed the title It is not possible to define a function with the same name as the parameter It is not possible to define a variable with the same name as the parameter Feb 11, 2025
@zerosnacks
Copy link

It is arguable that permitting the shadowing of variables is within spec even though the compiler raising a warning and is discouraged

Warning (2519): This declaration shadows an existing declaration.
 --> src/Counter.sol:8:9:
  |
8 |         int256 newNumber = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: this is a bug
Projects
None yet
Development

No branches or pull requests

3 participants