[Question] TypesMatchWith fails to verify type match

Hello everyone!
I’m currently implementing a dataflow-centered dialect. For that, I have an input type that represents the input end of a FIFO channel. An associated op is used to push items into the channel:

dfg.push(%value) %chan : (i32) -> !dfg.input<i32>

Since I want to ensure type correctness here, I want to model the constraint that the type of %value matches the inner type of %chan. So, I thought (after browsing the MLIR codebase and seeing this post) I can use TypesMatchWith for my purposes.

I implemented dfg.push like this:

def Dfg_PushOp : Dfg_Op<
    "push",
    [
        TypesMatchWith<"Channel type matches pushed type",
                       "chan", "inp",
                       "InputType::get($_ctxt, $_self).getElementType()">
    ]
> {
    // -- snip --
    let arguments = (ins AnyType: $inp, Dfg_InputType: $chan);
    let assemblyFormat = [{
        `(` $inp `)` $chan attr-dict `:` functional-type($inp, $chan)
    }];
}

def Dfg_InputType : Dfg_Type<"Input", []> {
    let mnemonic = "input";
    // -- snip --
    let parameters = (ins "Type":$elementType);
    let assemblyFormat = "`<` $elementType `>`";
}

However, a (in my opinion) correct code sample like the one above triggers the verification failure “failed to verify that Channel type matches pushed type”. Am I using TypesMatchWith incorrectly (which I assume) or is there a bug?

Thanks in advance for any hints!

// A type constraint that denotes `transform(lhs.getType()) == rhs.getType()`.
// An optional comparator function may be provided that changes the above form
// into: `comparator(transform(lhs.getType()), rhs.getType())`.
class TypesMatchWith<string summary, string lhsArg, string rhsArg,
                     string transform, string comparator = "std::equal_to<>()">

lhs here is chan, but chan is the input type, so I’d expect inp to be the one transformed with what you have there.

But isn’t that exactly what you’d want to do? I put chan on the lhs to then use the InputType::getElementType() getter and retrieve the type enclosed in the input, which should then be equal to the rhs.

Okay, I got it sorted out now. The issue indeed was here:

InputType::get is the wrong approach in this case. Instead, what you want is this:

$_self.cast<InputType>().getElementType()