Could you share a bit more of your code? I can’t spot anything in the snippet you posted but I suspect the way you use filteredByProductCode may be the problem.
It would be great if you could embed your code in a code block to make sure indentation is preserved and it’s easier to read. Just wrap it in triple backticks:
The issue is in the type of coverageType. First, remember that all branches in a case statement must have the same type.
Looking at the first branch, you return None. So coverageType must be of type Optional a for some type a. That’s the Optional a0 you see in the error.
Looking at the second branch, you return xs which is one of the elements of filteredByProductCode. filteredByProductCode must have the same type as coverageLayerList since filter doesn’t change the type of the list. But now we have a problem: life.coverage has type [Coverage_Type] so a single element has type Coverage_Type. But in the first branch, we said a single element must have type Optional a which doesn’t match. That’s exactly what the error is telling us.
Changing in (xs, …) to in (Some xs, …) should at least fix that type error, not sure if that’s what you intended.
The fact that errors sometimes don’t point at the location that you expect is one of the downsides of the relatively comprehensive type inference that Daml gives you. If an error seems confusing, I recommend to add more type annotations to narrow it down. E.g., in this case adding a type annotation to filteredByProductCode should narrow it down.