Skip to content

Namespace ambiguity with TimeoutError has to be resolved in a strange way #6

@gregcotten

Description

@gregcotten

In a situation where you import both FlyingSocks and Timeout

import FlyingSocks
import Timeout

and try to do something like

do {
    for try await message in socket.messages.timeout(seconds: 30) {}
} catch where error is TimeoutError {}

You get an error from the Swift compiler:
'TimeoutError' is ambiguous for type lookup in this context

Turns out FlyingSocks has its own (perhaps lagged-behind copy of) swift-timeout.

You might think you could resolve it by simply getting more specific by changing the catch to

catch where error is Timeout.TimeoutError {}

But since there is a struct named Timeout inside the package Timeout, you get another error, since it's confusing the struct and the name of the package:
'TimeoutError' is not a member type of struct 'Timeout.Timeout'

The only way to get Swift to build without error is to explicitly import the TimeoutError struct:

import FlyingSocks
import Timeout
import struct Timeout.TimeoutError

and change the line back to

catch where error is TimeoutError {}

I think the only fix I can think of involves changing the name of the (unfortunately public) struct Timeout to something that isn't the name of the package, perhaps TimeoutState, or something similar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions