Procházet zdrojové kódy

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

Geoff Romer před 2 měsíci
rodič
revize
b3d57aff7a
1 změnil soubory, kde provedl 12 přidání a 1 odebrání
  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`.