Branch: refs/heads/main
Revision: cb1bcde
Author: vasslitvinov
Link: Ensure the declared type of a formal is, indeed, a type by vasslitvinov · Pull Request #20299 · chapel-lang/chapel · GitHub
Log Message:
Merge pull request #20299 from vasslitvinov/arg-type-value
Ensure the declared type of a formal is, indeed, a type
This extends the checking introduced in #20262 to all formals.
After making a big deal out of it here:
https://github.com/chapel-lang/chapel/pull/20262#issuecomment-1190259631
I realized that maybe it is actually simple? Maybe indeed all we need
is to add a field bool typeExprFromDefaultExpr
to ArgSymbol
?
Turned out that it was not so simple after all. On the upside, I was
able to remove some heuristic code, replacing it with a
(non-heuristic) check for typeExprFromDefaultExpr
.
It took some work to handle the various ways a user may declare a
formal's type, see checkFormalType()
. I think that this code will
still miss some cases ex. when the formal's type is declared using a
value-producing primitive. The way it should be done is by flagging
the cases where the qualType()
of the formal's typeExpr is not a
QUAL_TYPE. However, our qualType() does not have the QUAL_TYPE option,
so we cannot do this at present. Luckily, Dyno gets it right with
QualifiedType::Kind::TYPE
.
While there, I added two futures asking about the behavior in some cases
where the formal's type is a runtime type, specifically an
array. These futures support the cause of #19292, showing another
example of where runtime types add complexity, albeit minor in this
case, to both the implementation and the language definition.
r: @dlongnecke-cray
Modified Files:
A test/functions/compilation-errors/value-for-arg-type.chpl
A test/functions/compilation-errors/value-for-arg-type.good
A test/functions/default-arguments/runtime-type-1.bad
A test/functions/default-arguments/runtime-type-1.chpl
A test/functions/default-arguments/runtime-type-1.future
A test/functions/default-arguments/runtime-type-1.good
A test/functions/default-arguments/runtime-type-2.bad
A test/functions/default-arguments/runtime-type-2.chpl
A test/functions/default-arguments/runtime-type-2.future
A test/functions/default-arguments/runtime-type-2.good
M compiler/AST/AggregateType.cpp
M compiler/AST/AstToText.cpp
M compiler/AST/FnSymbol.cpp
M compiler/AST/symbol.cpp
M compiler/include/AstToText.h
M compiler/include/symbol.h
M compiler/passes/normalize.cpp
Compare: https://github.com/chapel-lang/chapel/compare/12a697755fce...cb1bcdef478e