Skip to content

Commit d1e1287

Browse files
committed
Document and tidy Helpers.cc
1 parent 42493f4 commit d1e1287

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

ast/Helpers.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,19 +585,25 @@ class MK {
585585
static bool isRootScope(const ast::ExpressionPtr &scope) {
586586
if (ast::isa_tree<ast::EmptyTree>(scope)) {
587587
return true;
588+
} else if (auto root = ast::cast_tree<ast::ConstantLit>(scope)) {
589+
return root->symbol() == core::Symbols::root();
588590
}
589-
auto root = ast::cast_tree<ast::ConstantLit>(scope);
590-
return root != nullptr && root->symbol() == core::Symbols::root();
591+
592+
return false;
591593
}
592594

595+
// Detects references to the `::<Magic>` class. Since they're all created from `MK::Magic()`,
596+
// they should only ever be resolved `ConstantLit`s, and never `UnresolvedConstantLit`.
593597
static bool isMagicClass(const ExpressionPtr &expr) {
594598
if (auto recv = cast_tree<ConstantLit>(expr)) {
595599
return recv->symbol() == core::Symbols::Magic();
596-
} else {
597-
return false;
598600
}
601+
602+
return false;
599603
}
600604

605+
// Detects references to the `Sorbet::Private::Static` class. Since they're all created from
606+
// `MK::SorbetPrivateStatic()`, they should only ever be resolved `ConstantLit`s, and never `UnresolvedConstantLit`.
601607
static bool isSorbetPrivateStatic(const ast::ExpressionPtr &expr) {
602608
if (auto recv = cast_tree<ConstantLit>(expr)) {
603609
return recv->symbol() == core::Symbols::Sorbet_Private_Static();
@@ -606,6 +612,7 @@ class MK {
606612
return false;
607613
}
608614

615+
// Detects calls to `self.new`
609616
static bool isSelfNew(ast::Send *send) {
610617
return send->fun == core::Names::new_() && send->recv.isSelfReference();
611618
}
@@ -639,13 +646,19 @@ class MK {
639646
}
640647

641648
static bool isTNilable(const ast::ExpressionPtr &expr) {
642-
auto nilable = ast::cast_tree<ast::Send>(expr);
643-
return nilable != nullptr && nilable->fun == core::Names::nilable() && isTApproximate(nilable->recv);
649+
if (auto nilable = ast::cast_tree<ast::Send>(expr)) {
650+
return nilable->fun == core::Names::nilable() && isTApproximate(nilable->recv);
651+
}
652+
653+
return false;
644654
}
645655

646656
static bool isTUntyped(const ast::ExpressionPtr &expr) {
647-
auto send = ast::cast_tree<ast::Send>(expr);
648-
return send != nullptr && send->fun == core::Names::untyped() && isTApproximate(send->recv);
657+
if (auto send = ast::cast_tree<ast::Send>(expr)) {
658+
return send->fun == core::Names::untyped() && isTApproximate(send->recv);
659+
}
660+
661+
return false;
649662
}
650663

651664
static core::NameRef arg2Name(const ExpressionPtr &arg) {

0 commit comments

Comments
 (0)