[Chapel Merge] Stop ignoring declared types when initializing exp

Branch: refs/heads/main
Revision: d74a76f
Author: bradcray
Log Message:

Merge pull request #18225 from bradcray/fix-tuple-init-equals

Stop ignoring declared types when initializing expressions are tuples

[reviewed by @lydia-duncan]

This fixes a bug in our code base that Shreyas ran into, in which if a
variable's initializer is a tuple:

var r: T = (t1, t2);

then the type of the variable 'T' is completely ignored and 'r' is
treated as a tuple, as though it had been declared:

var r = (t1, t2);

The effect was that if T was a record with a copy initializer
accepting tuples, say, the type of T would be dropped on
the floor and the copy initializer never called.

It turns out that this was because when resolution found any
declaration initialized with a tuple, it rewrote the declaration
essentially as:

var r = initCopy((t1, t2));

Here, I only make this initCopy() rule fire if both the rhs and
lhs are tuple types, which is presumably what was intended.

This is one of those classic fixes where part of me thinks
"Are there other things we should be checking for before
applying this rule to tuples?" (like "same size?" "same element
type?") and/or "Are there other types in this conditional that
are similarly causing declared types to be ignored?" but in
the interest of not getting too distracted from my main tasks,
I'm considering this an improvement that doesn't break anything
in our testing system and leaving those questions open for
another day.

Resolves #18219.

Modified Files:
A test/types/records/init/copy/copyInitFromTuple.chpl

A test/types/records/init/copy/copyInitFromTuple.good
M compiler/resolution/functionResolution.cpp

Compare: https://github.com/chapel-lang/chapel/compare/46527cf0c710...d74a76fc1b10