Просмотр исходного кода

Diagnose if a NodeIdOneOf argument isn't a typed node. (#6738)

Geoff Romer 2 месяцев назад
Родитель
Сommit
b3d57aff7a
1 измененных файлов с 12 добавлено и 1 удалено
  1. 12 1
      toolchain/parse/node_ids.h

+ 12 - 1
toolchain/parse/node_ids.h

@@ -113,9 +113,20 @@ using AnyRequirementId = NodeIdInCategory<NodeCategory::Requirement>;
 using AnyNonExprNameId = NodeIdInCategory<NodeCategory::NonExprName>;
 using AnyPackageNameId = NodeIdInCategory<NodeCategory::PackageName>;
 
+namespace Internal {
+template <typename T>
+concept IsNodeKind = std::same_as<std::remove_cvref_t<T>, NodeKind> ||
+                     std::same_as<std::remove_cvref_t<T>, NodeKind::Definition>;
+
+template <typename T>
+concept IsTypedNode = requires {
+  { T::Kind } -> IsNodeKind;
+};
+}  // namespace Internal
+
 // NodeId with kind that matches one of the `T::Kind`s.
 template <typename... T>
-  requires(sizeof...(T) >= 2)
+  requires(sizeof...(T) >= 2 && (Internal::IsTypedNode<T> && ...))
 struct NodeIdOneOf : public NodeId {
  private:
   // True if `OtherT` is one of `T`.