Skip to content

Commit e39107e

Browse files
committed
error update when no init, type
Signed-off-by: Ahmad Rezaii <[email protected]>
1 parent a94b2f5 commit e39107e

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

frontend/include/chpl/resolution/resolution-error-classes-list.h

+1
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ ERROR_CLASS(UserDiagnosticEmitError, UniqueString, ID)
134134
WARNING_CLASS(UserDiagnosticEncounterWarning, UniqueString, ID)
135135
WARNING_CLASS(UserDiagnosticEmitWarning, UniqueString, ID)
136136
ERROR_CLASS(ValueUsedAsType, const uast::AstNode*, types::QualifiedType)
137+
ERROR_CLASS(VariableWithoutInitOrType, const uast::AstNode*, ID, chpl::UniqueString)

frontend/lib/resolution/call-init-deinit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void CallInitDeinit::resolveDefaultInit(const VarLikeDecl* ast, RV& rv) {
439439
return;
440440
}
441441
if (varType.isUnknownKindOrType()) {
442-
context->error(ast, "cannot default initialize variable using generic or unknown type");
442+
CHPL_REPORT(context, VariableWithoutInitOrType, ast, ast->id(), ast->name());
443443
return;
444444
}
445445
// check genericity

frontend/lib/resolution/copy-elision.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ struct FindElidedCopies : VarScopeVisitor {
102102
void handleThrow(const uast::Throw* ast, RV& rv) override;
103103
void handleYield(const uast::Yield* ast, RV& rv) override;
104104
void handleTry(const Try* t, RV& rv) override;
105-
106-
void handleDisjunction(const AstNode * node,
105+
106+
void handleDisjunction(const AstNode * node,
107107
VarFrame * currentFrame,
108-
const std::vector<VarFrame*>& frames,
108+
const std::vector<VarFrame*>& frames,
109109
bool total, RV& rv) override;
110-
110+
111111
void handleScope(const AstNode* ast, RV& rv) override;
112112
};
113113

@@ -179,10 +179,10 @@ FindElidedCopies::copyElisionAllowedForTypes(const QualifiedType& lhsType,
179179
RV& rv) {
180180
if (kindAllowsCopyElision(lhsType.kind()) &&
181181
kindAllowsCopyElision(rhsType.kind())) {
182-
if (lhsType.type() == rhsType.type()) {
183-
return true;
184-
} else if (lhsType.isUnknown() || rhsType.isUnknown()) {
182+
if (lhsType.isUnknown() || rhsType.isUnknown()) {
185183
return false;
184+
} else if (lhsType.type() == rhsType.type()) {
185+
return true;
186186
} else if (isRecordLike(lhsType.type())) {
187187
// check to see if an there is an init= to initialize
188188
// lhsType from rhsType but that uses the 'in' intent on the
@@ -428,8 +428,8 @@ static void propagateMentionsAndInits(VarFrame* parentFrame, VarFrame* childFram
428428

429429

430430
void FindElidedCopies::handleDisjunction(const AstNode * node,
431-
VarFrame * currentFrame,
432-
const std::vector<VarFrame*>& frames,
431+
VarFrame * currentFrame,
432+
const std::vector<VarFrame*>& frames,
433433
bool total, RV& rv) {
434434
// if any frame is 'param true' the rest of the frames do not matter
435435
for (auto frame : frames) {

frontend/lib/resolution/resolution-error-classes-list.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,10 @@ static void printRejectedCandidates(ErrorWriterBase& wr,
697697
!offendingActual->typeExpression()) {
698698
auto formalKind = badPass.formalType().kind();
699699
auto actualName = "'" + actualExpr->toIdentifier()->name().str() + "'";
700-
wr.message("The actual ", actualName,
700+
wr.note(offendingActual->id(), "The actual ", actualName,
701701
" expects to be split-initialized because it is declared without a type or initialization expression here:");
702702
wr.codeForDef(offendingActual);
703-
wr.message("The call to '", ci.name() ,"' occurs before any valid initialization points:");
703+
wr.note(actualExpr, "The call to '", ci.name() ,"' occurs before any valid initialization points:");
704704
wr.code(actualExpr, { actualExpr });
705705
actualPrinted = true;
706706
wr.message("The call to '", ci.name(), "' cannot initialize ",
@@ -2413,6 +2413,17 @@ void ErrorUseOfLaterVariable::write(ErrorWriterBase& wr) const {
24132413
wr.message("Variables cannot be referenced before they are defined.");
24142414
}
24152415

2416+
2417+
void ErrorVariableWithoutInitOrType::write(ErrorWriterBase& wr) const {
2418+
auto stmt = std::get<const uast::AstNode*>(info_);
2419+
auto& node = std::get<ID>(info_);
2420+
auto name = std::get<UniqueString>(info_);
2421+
wr.heading(kind_, type_, stmt,
2422+
"variable '", name, "' is declared without an initializer or type.");
2423+
wr.note(node, "cannot find initialization point to split-init this variable");
2424+
wr.codeForLocation(node);
2425+
}
2426+
24162427
void ErrorUserDiagnosticEncounterError::write(ErrorWriterBase& wr) const {
24172428
auto msg = std::get<UniqueString>(info_);
24182429
auto& node = std::get<ID>(info_);

0 commit comments

Comments
 (0)