diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -3622,6 +3622,14 @@ .append("previously defined here"); } + if (existing.getType() != value.getType()) { + return emitError(useInfo.loc) + .append("definition of SSA value '", useInfo.name, "#", + useInfo.number, "' has type ", value.getType()) + .attachNote(getEncodedSourceLocation(entries[useInfo.number].second)) + .append("previously specified type ", existing.getType()); + } + // If it was a forward reference, update everything that used it to use // the actual definition instead, delete the forward ref, and remove it // from our set of forward references we track. diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -1496,3 +1496,18 @@ // expected-error @+1 {{duplicate key in dictionary attribute}} "foo.op"() {a, a} : () -> () } + +// ----- + +func @forward_reference_type_check() -> (i8) { + br ^bb2 + +^bb1: + // expected-note @+1 {{previously specified type 'i8'}} + return %1 : i8 + +^bb2: + // expected-error @+1 {{definition of SSA value '%1#0' has type 'f32'}} + %1 = "bar"() : () -> (f32) + br ^bb1 +}