diff --git a/runtime/type-builtins.cpp b/runtime/type-builtins.cpp index a5f932f90..2b24e96ba 100644 --- a/runtime/type-builtins.cpp +++ b/runtime/type-builtins.cpp @@ -82,8 +82,16 @@ RawObject findBuiltinTypeWithName(Thread* thread, const Object& name) { Object layout(&scope, NoneType::object()); Object type_obj(&scope, NoneType::object()); for (int i = 0; i <= static_cast(LayoutId::kLastBuiltinId); i++) { - layout = runtime->layoutAtSafe(static_cast(i)); - if (layout.isErrorNotFound()) continue; + LayoutId id = static_cast(i); + if (id == LayoutId::kError) { + // layoutAt(LayoutId::kError) will fail. + continue; + } + layout = runtime->layoutAt(id); + if (layout == SmallInt::fromWord(0)) { + // Indicates an invalid LayoutId. + continue; + } type_obj = Layout::cast(*layout).describedType(); if (!type_obj.isType()) continue; if (Type::cast(*type_obj).name() == name) {