Branch: refs/heads/main
Revision: 6cdf82cd287eafaa929ae7dfb81655bb350ce3fe
Author: DanilaFe
Link: Allow type methods to shadow fields (+ implicit accessors) by DanilaFe · Pull Request #28600 · chapel-lang/chapel · GitHub
Log Message:
Allow type methods to shadow fields (+ implicit accessors) (#28600)
From the discussion there:
In the production compiler, we have code that detects user-defined
accessors for fields and tags them as such. So, a parenlessproc x,
which serves to 1) disable a compiler-generated accessor 2) tag the
user-defined accessor with some pragmas. This is why, in this case,
having the fieldxis important to trigger the issue.This check proceeds only by name, and does not distinguish
type
methods from non-typemethods. So, it stops us from generating
compiler-defined accessors, and adds some rather strange tags to the
typeproc that leads to odd errors.
This PR does the following:
- Adjusts Dyno to only perform field-shadowing checks for non-
type
methods (@jabraham17's patch) - In fact, I go a bit further than Jade's patch, to still emit errors
for user-declared parenless procedures that matchtypeandparam
fields. This is becausetypeandparamfields can be accessed via
the type, and not just the value. (R.typeFieldworks,R.valueField
does not) - Allows the search for overloads to skip over
typemethods (ones with
a type-variable receiver). Do this during the search so that we can keep
looking and find a "real" user-defined field accessor.
Reviewed by @jabraham17 -- thanks!
Testing
- paratest
Diff:
M compiler/passes/buildDefaultFunctions.cpp
M frontend/include/chpl/parsing/parsing-queries.h
M frontend/lib/parsing/parsing-queries.cpp
M frontend/lib/resolution/resolution-queries.cpp
A test/functions/shadowing/type-method-field-same-name.chpl
A test/functions/shadowing/type-method-field-same-name.good
A test/functions/shadowing/type-method-instance-method-field.chpl
A test/functions/shadowing/type-method-instance-method-field.good
A test/functions/shadowing/type-method-param-field.chpl
A test/functions/shadowing/type-method-param-field.good
A test/functions/shadowing/type-method-type-field.chpl
A test/functions/shadowing/type-method-type-field.good
https://github.com/chapel-lang/chapel/pull/28600.diff