-
Notifications
You must be signed in to change notification settings - Fork 423
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
should it be possible to shadow a symbol brought in with import? #19160
Comments
@lydia-duncan tells me that it is this way intentionally and that the rationale can be summarized as keeping |
I feel like I could live with either the current behavior or the proposed behavior here as long as we're only talking about imports and symbol definitions at the same scope and not cases where they're at staggered scopes like: import M.x;
{
var x = ...;
...x... // local var x should win here
} Even if we didn't go so far as making the cases in the OP an error, I think it could merit a warning since it seems that something is wrong in the code (either you didn't need to import it or you didn't mean to shadow it). Your examples also have the property that the function signatures are identical, but for the paren-ful subroutine case presumably I could add local overloads of a function using a different signature and call either version as appropriate (i.e., it would add to the overload set rather than eclipsing the imported version(s) of the procedure). |
Yes, and I agree. It seemed odd to me at first but I'm not convinced we need to change it, either.
Yes |
See #19167 |
In particular the relevant part is
which is saying that the ability to shadow a symbol brought in with import can be useful when using shadowing to resolve conflicts. I think the counter-argument to that is that you can just rename it when you import it e.g. |
It occurred to me to think about how From the last paragraph in https://chapel-lang.org/docs/language/spec/modules.html#conflicts :
But, both of the examples in the original post behave the same with So for And then, supposing we fixed |
Correcting something from #19160 (comment) The spec does indicate that public import introduces a shadow scope -- https://chapel-lang.org/docs/language/spec/modules.html#re-exporting
The earlier paragraph gave the impression it did not have a shadow scope but linked here. |
simplify use/import shadowing This PR describes and implements some candidate language adjustments to shadowing behavior for use and import statements. We need to do something in this area because the definition of shadowing is currently inconsistent between variables and functions (#19167). This PR attempts to simplify the language design in this area. The adjustments to the language design in this PR are as follows: * isMoreVisible in function disambiguation as well as scope resolution use the same rules for determining shadowing with use/import statements * isMoreVisible starts it search from the POI where the candidates were discovered (see issue #19198 -- not discussed further here) * private use statements still have two shadow scopes * public and private import statements now do not introduce a shadow scope * public use statements now do not introduce a shadow scope * `public use M` does not bring in `M` (but `public use M as M` does) * methods are no longer subject to shadowing Note that the above design leads to less shadowing of symbols from the automatic library (see the section "Less Shadowing of Symbols from the Automatic Standard Library" in #19306 (comment)) ## Discussion Elements of the language design direction are discussed in these issues: * #19167 * #19160 * #19219 and #13925 * #19312 * #19352 Please see also #19306 (comment) which discusses pros and cons of these language design choices. ### Testing and Review Reviewed by @lydia-duncan - thanks! This PR passes full local futures testing. Resolves the future `test/modules/vass/use-depth.chpl`. Also fixes #19198 and adds a test based on the case in that issue. - [x] full local futures testing - [x] gasnet testing ### Future Work There are two areas of future work that we would like to address soon: * #19313 which relates to changes in this PR to the test `modules/bradc/userInsteadOfStandard/foo2`. The behavior for trying to replace a standard module has changed (presumably due to minor changes in how the usual standard modules are now available). I think that changing the compiler to separately list each standard module would bring the behavior back the way it was. (Or we could look for other implementation changes to support it). * #19780 to add warnings for cases where the difference between `public use M` and `private use M` might be surprising
In https://chapel-lang.org/docs/language/spec/procedures.html#determining-more-specific-functions it says that X is more specific than Y if X shadows Y.
I can understand why "shadowing" should be allowed for a
use
statement but it is not so clear to me that we should allow it for the corresponding example withimport
.Here is an example with a function:
This compiles today and prints
M.f
. I think it should not compile, because I think ofimport
as creating a local symbol just like theproc
declaration does.Here is a similar example for scope resolution:
Which also compiles and prints
M
.Both of the above examples currently behave the same with
public import
.The text was updated successfully, but these errors were encountered: