Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6100] Compilation hangs when catching error with associated value defined inside generic class/struct #48655

Closed
kirilltitov opened this issue Oct 9, 2017 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@kirilltitov
Copy link

Previous ID SR-6100
Radar rdar://problem/34898452
Original Reporter @kirilltitov
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9A235 with up-to-date toolchain, Swift 4, also can be reproduced with 9.1 beta.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @DougGregor
Priority Medium

md5: 2afa1ba8acb94b57563aca83911d1edf

Issue Description:

It just freezes at 100% CPU and nothing happens.

import Foundation

// if you remove generic, everything works
struct One<Two> {
    public enum E: Error {
        // if you remove associated value, everything works
        case SomeError(String)
    }
}

do {
    // noop
} catch let error {
    // if you remove next line, everything works (this also could be done simplier, with just catch One.E.SomeError(let string))
    if case One.E.SomeError = error {}
}
@kirilltitov
Copy link
Author

The workaround could be specifying the generic value when catching the error, no matter what, it should just satisfy generic constraints (if any).

do {}
catch One<Error>.E.SomeError(let error) {}

So now I understand the problem. In my actual case I use the class generic as the associated value in error enum, and that said I must specify the type when referring to the error in catch. But in my sample code above the generic is referenced only once, and error enum case associated type is concrete, so I think in this case the generic reference could be omitted. Otherwise compile error should be triggered.

@belkadan
Copy link
Contributor

Crashes with assertions:

Bad base type
UNREACHABLE executed at /Volumes/Data/swift-public/swift/lib/AST/Type.cpp:3310!

7  swift                    0x00000001079d892a swift::TypeBase::getContextSubstitutions(swift::DeclContext const*, swift::GenericEnvironment*) + 906
8  swift                    0x00000001079d8b50 swift::TypeBase::getMemberSubstitutions(swift::ValueDecl const*, swift::GenericEnvironment*) + 128
9  swift                    0x00000001079d8d0b swift::TypeBase::getMemberSubstitutionMap(swift::ModuleDecl*, swift::ValueDecl const*, swift::GenericEnvironment*) + 75
10 swift                    0x00000001079d8dc0 swift::TypeBase::getTypeOfMember(swift::ModuleDecl*, swift::ValueDecl const*, swift::Type) + 80
11 swift                    0x0000000107695558 swift::TypeChecker::coercePatternToType(swift::Pattern*&, swift::DeclContext*, swift::Type, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, swift::TypeLoc, bool) + 5368
12 swift                    0x000000010764cbc7 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 551
13 swift                    0x000000010764d545 swift::TypeChecker::typeCheckStmtCondition(llvm::MutableArrayRef<swift::StmtConditionElement>&, swift::DeclContext*, swift::Diag<>) + 357

@swift-ci create

@belkadan
Copy link
Contributor

You do need to provide the generic parameter, since One<Int>.E and One<String>.E are different types in Swift. But the compiler should tell you that, of course.

@kirilltitov
Copy link
Author

Even when nested structure/entity/class is there just in namespacing purposes and totally unrelated to generic?

@belkadan
Copy link
Contributor

The compiler can't know whether it's unrelated or not. Or rather, it could, but then that decision could change on the fly if you start using the generic parameter inside a function body, and that would be a really weird way to break something you might be relying on.

@DougGregor
Copy link
Member

#12633

@DougGregor
Copy link
Member

ffd3423

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants