Skip to content

Dyno error for variable without init/type, split-init error notes #27038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ ERROR_CLASS(UserDiagnosticEmitError, UniqueString, ID)
WARNING_CLASS(UserDiagnosticEncounterWarning, UniqueString, ID)
WARNING_CLASS(UserDiagnosticEmitWarning, UniqueString, ID)
ERROR_CLASS(ValueUsedAsType, const uast::AstNode*, types::QualifiedType)
ERROR_CLASS(VariableWithoutInitOrType, const uast::AstNode*, ID, chpl::UniqueString)
2 changes: 1 addition & 1 deletion frontend/lib/resolution/call-init-deinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void CallInitDeinit::resolveDefaultInit(const VarLikeDecl* ast, RV& rv) {
return;
}
if (varType.isUnknownKindOrType()) {
context->error(ast, "cannot default initialize variable using generic or unknown type");
CHPL_REPORT(context, VariableWithoutInitOrType, ast, ast->id(), ast->name());
return;
}
// check genericity
Expand Down
15 changes: 13 additions & 2 deletions frontend/lib/resolution/resolution-error-classes-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,10 @@ static void printRejectedCandidates(ErrorWriterBase& wr,
!offendingActual->typeExpression()) {
auto formalKind = badPass.formalType().kind();
auto actualName = "'" + actualExpr->toIdentifier()->name().str() + "'";
wr.message("The actual ", actualName,
wr.note(offendingActual->id(), "The actual ", actualName,
" expects to be split-initialized because it is declared without a type or initialization expression here:");
wr.codeForDef(offendingActual);
wr.message("The call to '", ci.name() ,"' occurs before any valid initialization points:");
wr.note(actualExpr, "The call to '", ci.name() ,"' occurs before any valid initialization points:");
wr.code(actualExpr, { actualExpr });
actualPrinted = true;
wr.message("The call to '", ci.name(), "' cannot initialize ",
Expand Down Expand Up @@ -2413,6 +2413,17 @@ void ErrorUseOfLaterVariable::write(ErrorWriterBase& wr) const {
wr.message("Variables cannot be referenced before they are defined.");
}


void ErrorVariableWithoutInitOrType::write(ErrorWriterBase& wr) const {
auto stmt = std::get<const uast::AstNode*>(info_);
auto& node = std::get<ID>(info_);
auto name = std::get<UniqueString>(info_);
wr.heading(kind_, type_, stmt,
"variable '", name, "' is declared without an initializer or type.");
wr.note(node, "cannot find initialization point to split-init this variable");
wr.codeForLocation(node);
}

void ErrorUserDiagnosticEncounterError::write(ErrorWriterBase& wr) const {
auto msg = std::get<UniqueString>(info_);
auto& node = std::get<ID>(info_);
Expand Down