diff --git a/hilti/toolchain/include/ast/types/name.h b/hilti/toolchain/include/ast/types/name.h index 6f2ec27eb3..eb1b645540 100644 --- a/hilti/toolchain/include/ast/types/name.h +++ b/hilti/toolchain/include/ast/types/name.h @@ -2,8 +2,6 @@ #pragma once -#include -#include #include #include @@ -19,13 +17,16 @@ class Name : public UnqualifiedType { bool isBuiltIn() const { return _builtin; } // resolves recursively - UnqualifiedType* resolvedType() const { + UnqualifiedType* resolvedType(size_t recursion_depth = 0) const { if ( ! _resolved_type_index ) return nullptr; + if ( recursion_depth > 1000 ) + return nullptr; + auto t = context()->lookup(_resolved_type_index); if ( auto n = t->tryAs() ) - return n->resolvedType(); + return n->resolvedType(recursion_depth + 1); else return t; } diff --git a/hilti/toolchain/src/compiler/resolver.cc b/hilti/toolchain/src/compiler/resolver.cc index aee6aa1897..cfb027674d 100644 --- a/hilti/toolchain/src/compiler/resolver.cc +++ b/hilti/toolchain/src/compiler/resolver.cc @@ -66,7 +66,10 @@ struct VisitorPass1 : visitor::MutatingPostOrder { } if ( n->resolvedTypeIndex() ) { - if ( auto resolved = n->resolvedType(); resolved->isOnHeap() ) { + auto resolved = n->resolvedType(); + if ( ! resolved ) + n->addError(util::fmt("type %s cannot be resolved by its name", n->id())); + else if ( resolved->isOnHeap() ) { if ( auto qtype = n->parent()->tryAs() ) { auto replace = false; diff --git a/tests/Baseline/hilti.types.id.recursive/output b/tests/Baseline/hilti.types.id.recursive/output new file mode 100644 index 0000000000..6313b464f1 --- /dev/null +++ b/tests/Baseline/hilti.types.id.recursive/output @@ -0,0 +1,3 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +[error] <...>/recursive.hlt:6:15-6:20: type Direct cannot be resolved by its name +[error] hiltic: aborting after errors diff --git a/tests/hilti/types/id/recursive.hlt b/tests/hilti/types/id/recursive.hlt new file mode 100644 index 0000000000..ddb9655657 --- /dev/null +++ b/tests/hilti/types/id/recursive.hlt @@ -0,0 +1,8 @@ +# @TEST-EXEC-FAIL: ${HILTIC} -p %INPUT > output 2>&1 +# @TEST-EXEC: btest-diff output + +module Test { + +type Direct = Direct; + +}