// This source file is part of the Swift.org open source project
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -parse
// REQUIRES: asserts
func B<T{associatedtype B<T{}class A:B<T.B>class B<T

Add 💥 (😢 → 57, 😀 → 5107) in swift::ConformanceLookupTable::lookupConformances(…)
Add 💥 (😢 → 57, 😀 → 5107) in swift::ConformanceLookupTable::lookupConformances(…)

Add test case for crash triggered in `swift::ConformanceLookupTable::lookupConformances(…)`.

Assertion failure in `llvm/include/llvm/ADT/Optional.h (line 120)`:

```
Assertion `hasVal' failed.

When executing: T *llvm::Optional<swift::ProtocolConformanceRef>::getPointer() [T = swift::ProtocolConformanceRef]
```

<details>
<summary>Assertion context:</summary>
```
    if (!O)
      reset();
    else
      *this = *O;
    return *this;
  }

  void reset() {
    if (hasVal) {
      (**this).~T();
      hasVal = false;
    }
  }

  ~Optional() {
    reset();
  }

  const T* getPointer() const { assert(hasVal); return reinterpret_cast<const T*>(storage.buffer); }
  T* getPointer() { assert(hasVal); return reinterpret_cast<T*>(storage.buffer); }
```
</details>
<details>
<summary>Stack trace:</summary>
```
swift: /path/to/llvm/include/llvm/ADT/Optional.h:120: T *llvm::Optional<swift::ProtocolConformanceRef>::getPointer() [T = swift::ProtocolConformanceRef]: Assertion `hasVal' failed.
10 swift           0x0000000001133ef4 swift::ConformanceLookupTable::lookupConformances(swift::NominalTypeDecl*, swift::DeclContext*, swift::LazyResolver*, swift::ConformanceLookupKind, llvm::SmallVectorImpl<swift::ProtocolDecl*>*, llvm::SmallVectorImpl<swift::ProtocolConformance*>*, llvm::SmallVectorImpl<swift::ConformanceDiagnostic>*) + 692
11 swift           0x0000000001116274 swift::DeclContext::getLocalConformances(swift::ConformanceLookupKind, llvm::SmallVectorImpl<swift::ConformanceDiagnostic>*, bool) const + 212
12 swift           0x0000000000efa8fa swift::TypeChecker::findWitnessedObjCRequirements(swift::ValueDecl const*, bool) + 122
14 swift           0x0000000000eaeedb swift::markAsObjC(swift::TypeChecker&, swift::ValueDecl*, llvm::Optional<swift::ObjCReason>, llvm::Optional<swift::ForeignErrorConvention>) + 987
17 swift           0x0000000000eb1686 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 150
18 swift           0x0000000000f32dbe swift::TypeChecker::addImplicitDestructor(swift::ClassDecl*) + 126
21 swift           0x0000000000eb1686 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 150
24 swift           0x0000000000f17bca swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 346
25 swift           0x0000000000f17a2e swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 46
26 swift           0x0000000000f185f3 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 179
28 swift           0x0000000000ed38e1 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1281
29 swift           0x0000000000c60b89 swift::CompilerInstance::performSema() + 3289
31 swift           0x00000000007d8429 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2857
32 swift           0x00000000007a4458 main + 2872
Stack dump:
0.	Program arguments: /path/to/swift/bin/swift -frontend -c -primary-file validation-test/compiler_crashers/28354-swift-conformancelookuptable-lookupconformances.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -module-name main -o /tmp/28354-swift-conformancelookuptable-lookupconformances-9d940c.o
1.	While type-checking 'B' at validation-test/compiler_crashers/28354-swift-conformancelookuptable-lookupconformances.swift:10:1
2.	While type-checking 'A' at validation-test/compiler_crashers/28354-swift-conformancelookuptable-lookupconformances.swift:10:30
3.	While type-checking 'deinit' at validation-test/compiler_crashers/28354-swift-conformancelookuptable-lookupconformances.swift:10:36
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
```
</details>
