Branch: refs/heads/main
Revision: 2ca4dc6
Author: mppf
Link: Warn for misleading 'new' pattern by mppf · Pull Request #20483 · chapel-lang/chapel · GitHub
Log Message:
Merge pull request #20483 from mppf/warn-misleading-new
Warn for misleading 'new' pattern
For
- https://github.com/Cray/chapel-private/issues/3674
- https://github.com/Cray/chapel-private/issues/3680
This PR adds a warning for patterns like
var x: borrowed C = new C(); // warn
x = new shared C(); // warn
including in variable initialization, split init, and assignment cases.
What happens in these patterns in that the result of the new
expression
is stored into a temporary variable and then that is borrowed from. That
is because we have implicit conversions from owned/shared to borrowed. It
is unlikely that this pattern is useful (specifically when the RHS is a
new
expression) and so this PR adds a warning for that case.
Reviewed by @daviditen - thanks!
-
full local testing
Modified Files:
A test/classes/errors/warn-misleading-new-unmanaged.chpl
A test/classes/errors/warn-misleading-new-unmanaged.good
A test/classes/errors/warn-misleading-new.chpl
A test/classes/errors/warn-misleading-new.good
M compiler/resolution/functionResolution.cpp
M test/classes/delete-free/borrowed/coercions-to-init-borrowed.chpl
M test/classes/delete-free/coercions-generic.chpl
M test/classes/delete-free/coercions-shared.chpl
M test/classes/delete-free/lifetimes/record-borrows.chpl
M test/classes/delete-free/lifetimes/stecil-setup.chpl
M test/classes/delete-free/tests-from-design-overview/new-myclass.chpl
M test/classes/ferguson/generic-field/generic-field-unmanaged-borrowed.chpl
M test/classes/initializers/generics/phase1/hasLoopGood.chpl
M test/classes/lydia/staticMethodInheritance-whenField.chpl
M test/classes/vass/ref-like-intents/inout-subclass.good
M test/classes/vass/ref-like-intents/ref-subclass.good
M test/classes/waynew/dyndis2.chpl
M test/modules/diten/mutualuse2.chpl
M test/trivial/jturner/iter_overload_simple.chpl
M test/visibility/private/uses/accessSecondary.chpl
M test/visibility/private/uses/accessSecondary.good
M test/visibility/private/uses/pointOfInstantiation/methodOnType2.chpl
M test/visibility/private/uses/pointOfInstantiation/methodOnType2.goodCompare: Comparing d5d6eded2306...2ca4dc69286f · chapel-lang/chapel · GitHub