diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -333,6 +333,13 @@ code builderCall = builder; } +// A type that's buildable iff the type passed as an argument is buildable. +// This is intended for use by types like container types, which are only +// buildable if the type of their elements is buildable. +class SameBuildabilityAs { + code builderCall = !if(!empty(type.builderCall), "", builder); +} + // Any type at all. def AnyType : Type, "any type">; @@ -479,7 +486,9 @@ "$_self.cast<::mlir::ComplexType>().getElementType()", type.predicate>]>, "complex type with " # type.description # " elements", - "::mlir::ComplexType"> { + "::mlir::ComplexType">, + SameBuildabilityAs { Type elementType = type; } diff --git a/mlir/test/mlir-tblgen/types.mlir b/mlir/test/mlir-tblgen/types.mlir --- a/mlir/test/mlir-tblgen/types.mlir +++ b/mlir/test/mlir-tblgen/types.mlir @@ -58,7 +58,7 @@ // ----- func @complex_f64_failure() { - // expected-error@+1 {{must be complex type with 64-bit float elements}} + // expected-error@+1 {{op inferred type incompatible with return type of operation}} "test.complex_f64"() : () -> (f64) return }