Skip to content

[Bug]: Invalid type checking for service declarations with union service types #44184

@MaryamZi

Description

@MaryamZi

Description

$title.

Steps to Reproduce

import ballerina/io;

type Foo distinct service object {
    isolated function get() returns string|error;
};

type Bar distinct service object {
    
};

public class Listener {

    public function 'start() returns error? {
    }

    public function gracefulStop() returns error? {
    }

    public function immediateStop() returns error? {
    }

    public function detach(Foo|Bar s) returns error? {
    }

    public function attach(Foo|Bar s, string[]|string|() name = ()) returns error? {
        io:println(s is Foo);
        io:println(s is Bar);
        io:println(s is Foo|Bar);
    }
}


service on new Listener() {

    isolated function get() returns string|error {
        return "";
    }

}

All the is checks evaluate to false. This particular example should probably fail at compile-time due to ambiguity anyway.

But, even for the following types, prints false for both.

type Foo distinct service object {
    isolated function get() returns string|error;
};

type Bar distinct service object {
    isolated function get() returns int|error;
};

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Team/CompilerFEAll issues related to Language implementation and Compiler, this exclude run times.Type/BugneedTriageThe issue has to be inspected and labeled manuallyuserCategory/Compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions