Skip to content

Commit fdec149

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

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
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/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)