[Chapel Merge] Allow type methods to shadow fields (+ implicit accessors)

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)

Closes [Bug]: Incorrect error for type method with same name as field · Issue #28599 · chapel-lang/chapel · GitHub.

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 parenless proc 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 field x is important to trigger the issue.

This check proceeds only by name, and does not distinguish type
methods from non-type methods. So, it stops us from generating
compiler-defined accessors, and adds some rather strange tags to the
type proc 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 match type and param
    fields. This is because type and param fields can be accessed via
    the type, and not just the value. (R.typeField works, R.valueField
    does not)
  • Allows the search for overloads to skip over type methods (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

Compare: Comparing 6c1c093c2f9f326a31f788ee06e1c64d6e764ebb...6451f170d189e0ed24bc3ef476b568817c5034e2 · chapel-lang/chapel · GitHub

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