Common Type Deduction Of Operator `Or` Expressions Is Incorrect When Result Type Is Class Derived From Interface And A Child Of Class

Reference ID

fcf8c0b6-4e77-a5bd-8819-22b85bd4e4ef

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

Verse

Summary

Common Type Deduction Of Operator Or Expressions Is Incorrect When Result Type Is Class Derived From Interface And A Child Of Class

Steps to Reproduce

See min repro code:

my_interface := interface
{
    DoSomething<public>()<transacts>:int
}

item<public> := class(my_interface)
{
    DoSomething<override>()<transacts>:int = 1
}

sub_item<public> := class(item)
{
    DoSomething<override>()<transacts>:int = 1
}

TestFunction(OptItem:?item):void =
{
    Item:item = OptItem? or sub_item{}
}

TestFunction() cannot compile as the assignment to Item:item fails due to the deduced common type being “any” instead of the common base “item”:

This variable expects to be initialized with a value of type item, but this initializer is an incompatible value of type any.(3509)

Expected Result

This code should be compile. It can be worked around by upcasting the child class to the parent class explicitly.

TestFunction(OptItem:?item):void =
{
    Item:item = OptItem? or item(sub_item{})
}

Observed Result

This code does not compile.

This variable expects to be initialized with a value of type item, but this initializer is an incompatible value of type any.(3509)

Platform(s)

windows

Bumping this issue, it is still occurring as of 28.00

Bumping this issue, it is still occurring as of 28.01

Bumping this issue, it is still occurring as of [insert current version here].

The status of UCB-1229 incident has been moved from ‘Awaiting Validation’ to ‘Closed’. Resolution Reason: ‘Duplicate’

For further reference this issue appears to stem from a more general problem with implicit type coercion from child class to parent interface not occurring when the child class is not a direct descendent of the parent interface (e.g. parent interface to child class is introduced from a parent class)

Bumping this issue, it is still occurring as of [insert current version here].