8000 rbs: beginError → beginIndexerError by jez · Pull Request #8873 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

rbs: beginError → beginIndexerError #8873

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

Merged
merged 2 commits into from
May 14, 2025
Merged
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
10 changes: 6 additions & 4 deletions rbs/AssertionsRewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ optional<rbs::InlineComment> AssertionsRewriter::commentForNode(unique_ptr<parse

void AssertionsRewriter::checkDanglingCommentWithDecl(uint32_t nodeEnd, uint32_t declEnd, string kind) {
if (auto assertion = commentForPos(nodeEnd)) {
if (auto e = ctx.beginError(assertion.value().comment.commentLoc, core::errors::Rewriter::RBSAssertionError)) {
if (auto e = ctx.beginIndexerError(assertion.value().comment.commentLoc,
core::errors::Rewriter::RBSAssertionError)) {
e.setHeader("Unexpected RBS assertion comment found after `{}` end", kind);
}
}
Expand All @@ -393,8 +394,8 @@ void AssertionsRewriter::checkDanglingCommentWithDecl(uint32_t nodeEnd, uint32_t

if ((endLine > decLine)) {
if (auto assertion = commentForPos(declEnd)) {
if (auto e =
ctx.beginError(assertion.value().comment.commentLoc, core::errors::Rewriter::RBSAssertionError)) {
if (auto e = ctx.beginIndexerError(assertion.value().comment.commentLoc,
core::errors::Rewriter::RBSAssertionError)) {
e.setHeader("Unexpected RBS assertion comment found after `{}` declaration", kind);
}
}
Expand All @@ -403,7 +404,8 @@ void AssertionsRewriter::checkDanglingCommentWithDecl(uint32_t nodeEnd, uint32_t

void AssertionsRewriter::checkDanglingComment(uint32_t nodeEnd, string kind) {
if (auto assertion = commentForPos(nodeEnd)) {
if (auto e = ctx.beginError(assertion.value().comment.commentLoc, core::errors::Rewriter::RBSAssertionError)) {
if (auto e = ctx.beginIndexerError(assertion.value().comment.commentLoc,
core::errors::Rewriter::RBSAssertionError)) {
e.setHeader("Unexpected RBS assertion comment found after `{}`", kind);
}
}
Expand Down
2 changes: 1 addition & 1 deletion rbs/CommentsAssociator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void CommentsAssociator::consumeCommentsUntilLine(int line) {
if (it->first < line) {
if (absl::StartsWith(it->second.string, RBS_PREFIX) ||
absl::StartsWith(it->second.string, MULTILINE_RBS_PREFIX)) {
if (auto e = ctx.beginError(it->second.loc, core::errors::Rewriter::RBSUnusedComment)) {
if (auto e = ctx.beginIndexerError(it->second.loc, core::errors::Rewriter::RBSUnusedComment)) {
e.setHeader("Unused RBS signature comment. No method definition found after it");
}
}
Expand Down
10 changes: 5 additions & 5 deletions rbs/MethodTypeToParserNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ unique_ptr<parser::Node> MethodTypeToParserNode::methodSignature(const parser::N

if (node.type->type != RBS_TYPES_FUNCTION) {
auto errLoc = declaration.typeLocFromRange(node.type->location->rg);
if (auto e = ctx.beginError(errLoc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(errLoc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("Unexpected node type `{}` in method signature, expected `{}`", rbs_node_type_name(node.type),
"Function");
}
Expand Down Expand Up @@ -398,7 +398,7 @@ unique_ptr<parser::Node> MethodTypeToParserNode::methodSignature(const parser::N
auto type = typeToParserNode.toParserNode(arg.type, declaration);

if (!methodArgs || i >= methodArgs->args.size()) {
if (auto e = ctx.beginError(fullTypeLoc, core::errors::Rewriter::RBSParameterMismatch)) {
if (auto e = ctx.beginIndexerError(fullTypeLoc, core::errors::Rewriter::RBSParameterMismatch)) {
e.setHeader("RBS signature has more parameters than in the method definition");
}

Expand All @@ -408,7 +408,7 @@ unique_ptr<parser::Node> MethodTypeToParserNode::methodSignature(const parser::N
auto methodArg = methodArgs->args[i].get();

if (!checkParameterKindMatch(arg, methodArg)) {
if (auto e = ctx.beginError(arg.loc, core::errors::Rewriter::RBSIncorrectParameterKind)) {
if (auto e = ctx.beginIndexerError(arg.loc, core::errors::Rewriter::RBSIncorrectParameterKind)) {
e.setHeader("Argument kind mismatch for `{}`, method declares `{}`, but RBS signature declares `{}`",
nodeName(methodArg).show(ctx.state), nodeKindToString(methodArg),
argKindToString(arg.kind));
Expand Down Expand Up @@ -496,7 +496,7 @@ unique_ptr<parser::Node> MethodTypeToParserNode::attrSignature(const parser::Sen
sigBuilder = handleAnnotations(std::move(sigBuilder), annotations);

if (send->args.size() == 0) {
if (auto e = ctx.beginError(send->loc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(send->loc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("RBS signatures do not support accessor without arguments");
}

Expand All @@ -508,7 +508,7 @@ unique_ptr<parser::Node> MethodTypeToParserNode::attrSignature(const parser::Sen

if (send->method == core::Names::attrWriter()) {
if (send->args.size() > 1) {
if (auto e = ctx.beginError(send->loc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(send->loc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("RBS signatures for attr_writer do not support multiple arguments");
}

Expand Down
12 changes: 6 additions & 6 deletions rbs/SignatureTranslator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SignatureTranslator::translateAssertionType(vector<std::pair<core::LocOffsets, c

if (parser.hasError()) {
core::LocOffsets loc = assertion.typeLocFromRange(parser.getError()->token.range);
if (auto e = ctx.beginError(loc, core::errors::Rewriter::RBSSyntaxError)) {
if (auto e = ctx.beginIndexerError(loc, core::errors::Rewriter::RBSSyntaxError)) {
e.setHeader("Failed to parse RBS type ({})", parser.getError()->message);
}
return nullptr;
Expand All @@ -54,11 +54,11 @@ unique_ptr<parser::Node> SignatureTranslator::translateAttrSignature(const parse
methodParser.parseMethodType();

if (!methodParser.hasError()) {
if (auto e = ctx.beginError(offset, core::errors::Rewriter::RBSSyntaxError)) {
if (auto e = ctx.beginIndexerError(offset, core::errors::Rewriter::RBSSyntaxError)) {
e.setHeader("Using a method signature on an accessor is not allowed, use a bare type instead");
}
} else {
if (auto e = ctx.beginError(offset, core::errors::Rewriter::RBSSyntaxError)) {
if (auto e = ctx.beginIndexerError(offset, core::errors::Rewriter::RBSSyntaxError)) {
e.setHeader("Failed to parse RBS type ({})", methodParser.getError()->message);
}
}
Expand All @@ -83,7 +83,7 @@ unique_ptr<parser::Node> SignatureTranslator::translateMethodSignature(const par
rbs_range_t tokenRange = parser.getError()->token.range;
core::LocOffsets offset = declaration.typeLocFromRange(tokenRange);

if (auto e = ctx.beginError(offset, core::errors::Rewriter::RBSSyntaxError)) {
if (auto e = ctx.beginIndexerError(offset, core::errors::Rewriter::RBSSyntaxError)) {
e.setHeader("Failed to parse RBS signature ({})", parser.getError()->message);
}

Expand All @@ -103,7 +103,7 @@ unique_ptr<parser::Node> SignatureTranslator::translateType(const RBSDeclaration

if (parser.hasError()) {
core::LocOffsets offset = declaration.typeLocFromRange(parser.getError()->token.range);
if (auto e = ctx.beginError(offset, core::errors::Rewriter::RBSSyntaxError)) {
if (auto e = ctx.beginIndexerError(offset, core::errors::Rewriter::RBSSyntaxError)) {
e.setHeader("Failed to parse RBS type ({})", parser.getError()->message);
}

Expand All @@ -125,7 +125,7 @@ parser::NodeVec SignatureTranslator::translateTypeParams(const RBSDeclaration &d
rbs_range_t tokenRange = parser.getError()->token.range;
core::LocOffsets offset = declaration.typeLocFromRange(tokenRange);

if (auto e = ctx.beginError(offset, core::errors::Rewriter::RBSSyntaxError)) {
if (auto e = ctx.beginIndexerError(offset, core::errors::Rewriter::RBSSyntaxError)) {
e.setHeader("Failed to parse RBS type parameters ({})", parser.getError()->message);
}

Expand Down
10 changes: 6 additions & 4 deletions rbs/SigsRewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ void SigsRewriter::insertTypeParams(parser::Node *node, unique_ptr<parser::Node>
}

if (comments.signatures.size() > 1) {
if (auto e = ctx.beginError(comments.signatures[0].commentLoc(),
core::errors::Rewriter::RBSMultipleGenericSignatures)) {
if (auto e = ctx.beginIndexerError(comments.signatures[0].commentLoc(),
core::errors::Rewriter::RBSMultipleGenericSignatures)) {
e.setHeader("Generic classes and modules can only have one RBS generic signature");
return;
}
Expand Down Expand Up @@ -265,7 +265,8 @@ Comments SigsRewriter::commentsForNode(parser::Node *node) {
// If the comment starts with `#:`, it's a signature
if (absl::StartsWith(commentNode.string, "#:")) {
if (state == SignatureState::Multiline) {
if (auto e = ctx.beginError(commentNode.loc, core::errors::Rewriter::RBSMultilineMisformatted)) {
if (auto e =
ctx.beginIndexerError(commentNode.loc, core::errors::Rewriter::RBSMultilineMisformatted)) {
e.setHeader("Signature start (\"#:\") cannot appear after a multiline signature (\"#|\")");
return comments;
}
Expand Down Expand Up @@ -293,7 +294,8 @@ Comments SigsRewriter::commentsForNode(parser::Node *node) {
// If the comment starts with `#|`, it's a multiline signature
if (absl::StartsWith(commentNode.string, "#|")) {
if (state == SignatureState::None) {
if (auto e = ctx.beginError(commentNode.loc, core::errors::Rewriter::RBSMultilineMisformatted)) {
if (auto e =
ctx.beginIndexerError(commentNode.loc, core::errors::Rewriter::RBSMultilineMisformatted)) {
e.setHeader("Multiline signature (\"#|\") must be preceded by a signature start (\"#:\")");
return comments;
}
Expand Down
2 changes: 1 addition & 1 deletion rbs/TypeParamsToParserNodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parser::NodeVec TypeParamsToParserNode::typeParams(const rbs_node_list_t *rbsTyp
auto loc = declaration.typeLocFromRange(list_node->node->location->rg);

if (rbsTypeParam->unchecked) {
if (auto e = ctx.beginError(loc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(loc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("`{}` type parameters are not supported by Sorbet", "unchecked");
}
}
Expand Down
20 changes: 10 additions & 10 deletions rbs/TypeToParserNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ unique_ptr<parser::Node> TypeToParserNode::functionType(const rbs_types_function
unique_ptr<parser::Node> innerType;

if (paramNode->type != RBS_TYPES_FUNCTION_PARAM) {
if (auto e = ctx.beginError(loc, core::errors::Internal::InternalError)) {
if (auto e = ctx.beginIndexerError(loc, core::errors::Internal::InternalError)) {
e.setHeader("Unexpected node type `{}` in function parameter type, expected `{}`",
rbs_node_type_name(paramNode), "FunctionParam");
}
Expand Down Expand Up @@ -204,7 +204,7 @@ unique_ptr<parser::Node> TypeToParserNode::procType(const rbs_types_proc_t *node
}
default: {
auto errLoc = declaration.typeLocFromRange(functionTypeNode->location->rg);
if (auto e = ctx.beginError(errLoc, core::errors::Internal::InternalError)) {
if (auto e = ctx.beginIndexerError(errLoc, core::errors::Internal::InternalError)) {
e.setHeader("Unexpected node type `{}` in proc type, expected `{}`",
rbs_node_type_name(functionTypeNode), "Function");
}
Expand Down Expand Up @@ -235,7 +235,7 @@ unique_ptr<parser::Node> TypeToParserNode::blockType(const rbs_types_block_t *no
}
default: {
auto errLoc = declaration.typeLocFromRange(functionTypeNode->location->rg);
if (auto e = ctx.beginError(errLoc, core::errors::Internal::InternalError)) {
if (auto e = ctx.beginIndexerError(errLoc, core::errors::Internal::InternalError)) {
e.setHeader("Unexpected node type `{}` in block type, expected `{}`",
rbs_node_type_name(functionTypeNode), "Function");
}
Expand Down Expand Up @@ -293,7 +293,7 @@ unique_ptr<parser::Node> TypeToParserNode::recordType(const rbs_types_record_t *
break;
}
default: {
if (auto e = ctx.beginError(loc, core::errors::Internal::InternalError)) {
if (auto e = ctx.beginIndexerError(loc, core::errors::Internal::InternalError)) {
e.setHeader("Unexpected node type `{}` in record key type, expected `{}`",
rbs_node_type_name(hash_node->key), "Symbol");
}
Expand All @@ -302,7 +302,7 @@ unique_ptr<parser::Node> TypeToParserNode::recordType(const rbs_types_record_t *
}

if (hash_node->value->type != RBS_TYPES_RECORD_FIELD_TYPE) {
if (auto e = ctx.beginError(loc, core::errors::Internal::InternalError)) {
if (auto e = ctx.beginIndexerError(loc, core::errors::Internal::InternalError)) {
e.setHeader("Unexpected node type `{}` in record value type, expected `{}`",
rbs_node_type_name(hash_node->value), "RecordFieldtype");
}
Expand All @@ -329,7 +329,7 @@ unique_ptr<parser::Node> TypeToParserNode::toParserNode(const rbs_node_t *node,
auto nodeLoc = declaration.typeLocFromRange(((rbs_node_t *)node)->location->rg);
switch (node->type) {
case RBS_TYPES_ALIAS: {
if (auto e = ctx.beginError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("RBS aliases are not supported");
}
return parser::MK::TUntyped(nodeLoc);
Expand All @@ -341,7 +341,7 @@ unique_ptr<parser::Node> TypeToParserNode::toParserNode(const rbs_node_t *node,
case RBS_TYPES_BASES_BOTTOM:
return parser::MK::TNoReturn(nodeLoc);
case RBS_TYPES_BASES_CLASS: {
if (auto e = ctx.beginError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("RBS type `{}` is not supported", "class");
}
return parser::MK::TUntyped(nodeLoc);
Expand All @@ -365,15 +365,15 @@ unique_ptr<parser::Node> TypeToParserNode::toParserNode(const rbs_node_t *node,
case RBS_TYPES_FUNCTION:
return functionType((rbs_types_function_t *)node, nodeLoc, declaration);
case RBS_TYPES_INTERFACE: {
if (auto e = ctx.beginError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("RBS interfaces are not supported");
}
return parser::MK::TUntyped(nodeLoc);
}
case RBS_TYPES_INTERSECTION:
return intersectionType((rbs_types_intersection_t *)node, nodeLoc, declaration);
case RBS_TYPES_LITERAL: {
if (auto e = ctx.beginError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
if (auto e = ctx.beginIndexerError(nodeLoc, core::errors::Rewriter::RBSUnsupported)) {
e.setHeader("RBS literal types are not supported");
}
return parser::MK::TUntyped(nodeLoc);
Expand All @@ -391,7 +391,7 @@ unique_ptr<parser::Node> TypeToParserNode::toParserNode(const rbs_node_t *node,
case RBS_TYPES_VARIABLE:
return variableType((rbs_types_variable_t *)node, nodeLoc);
default: {
if (auto e = ctx.beginError(nodeLoc, core::errors::Internal::InternalError)) {
if (auto e = ctx.beginIndexerError(nodeLoc, core::errors::Internal::InternalError)) {
e.setHeader("Unexpected node type `{}`", rbs_node_type_name((rbs_node_t *)node));
}

Expand Down
0