Karetski
(Alexey Karetski)
1
At first I want to show code example:
public struct Some<Type> {
private let instance: Type?
public enum Error: Swift.Error {
case some(instance: Type?)
}
public init(_ instance: Type?) {
self.instance = instance
}
public func make() throws {
throw Error.some(instance: instance)
}
}
And:
do {
try Some("String").make()
} catch Some.Error.some(let instance) {
print("\(instance)")
} catch { }
The code above will run your swift build forever, and only way to stop it is force quit swift process using Activity Monitor. I understand that the following code shouldn't work, even in theory, but in my opinion there should be some kind of compile time error or something.
And also I should mention that if we remove this part:
do {
try Some("String").make()
} catch Some.Error.some(let instance) {
print("\(instance)")
} catch { }
Or at least replace it with:
do {
try Some("String").make()
} catch {
}
Everything goes ok. There is no even compile-time error, which is strange.
tkrajacic
(Thomas Krajacic)
2
A quick search didn't turn up a bug for that so would you mind filing a new one at https://bugs.swift.org please?
DaveZ
(David Zarzycki)
4
This doesn't seem to hang on top-of-tree:
/tmp/t.swift:20:21: error: generic enum type 'Some.Error' is ambiguous without explicit generic parameters when matching value of type 'Error'
} catch Some.Error.some(let instance) {
^
/tmp/t.swift:19:3: error: errors thrown from here are not handled because the enclosing catch is not exhaustive
try Some("String").make()
^
Karetski
(Alexey Karetski)
5
Sorry, It seems like I forgot to add another catch to the example. The final version should look like this:
do {
try Some("String").make()
} catch Some.Error.some(let instance) {
print("\(instance)")
} catch { }
DaveZ
(David Zarzycki)
6
That generates the following with top-of-tree:
/tmp/t.swift:20:22: error: generic enum type 'Some.Error' is ambiguous without explicit generic parameters when matching value of type 'Error'
} catch Some.Error.some(let instance) {
^
Karetski
(Alexey Karetski)
7
Hmm... It looks strange. Can you please check my Example GitHub - Karetski/ExampleSwiftInfiniteCompile to build?
DaveZ
(David Zarzycki)
8
Still fails. NOTE: ~/s/u/dt/bin/swift is a freshly built RelWithDebInfo build.
dell:/tmp 0 $ git clone https://github.com/Karetski/Example
Cloning into 'Example'...
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 13 (delta 1), reused 13 (delta 1), pack-reused 0
Unpacking objects: 100% (13/13), done.
dell:/tmp 0 $ cd Example/
dell:/tmp/Example 0 $ ~/s/u/dt/bin/swift ./Example.swift
./Example.swift:19:20: error: generic enum type 'Some.Error' is ambiguous without explicit generic parameters when matching value of type 'Error'
} catch Some.Error.some(let instance) {
^
./Example.swift:18:5: warning: no calls to throwing functions occur within 'try' expression
try Some("String").make()
^
./Example.swift:19:3: warning: 'catch' block is unreachable because no errors are thrown in 'do' block
} catch Some.Error.some(let instance) {
^
./Example.swift:13:9: error: error is not handled because the enclosing function is not declared 'throws'
throw Error.some(instance: instance)
^
dell:/tmp/Example 1 $ ~/s/u/dt/bin/swift ./Sources/Example/Example.swift
./Sources/Example/Example.swift:21:28: error: generic enum type 'Some.Error' is ambiguous without explicit generic parameters when matching value of type 'Error'
} catch Some.Error.some(let instance) {
^
dell:/tmp/Example 1 $
Karetski
(Alexey Karetski)
9
Seems like this issue was fixed recently, since I'm using the version that is supplied with Xcode 9.2 on macOS 10.13.3:
Alexeys-MacBook-Pro:Example Karetski$ swift --version
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9
Or maybe there could be some other reasons? I'm not so experienced in this question.
Karetski
(Alexey Karetski)
10
I see the following even when just open Xcode project of this package
Karetski
(Alexey Karetski)
11
Tried to reproduce the same issue on:
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
And it looks like it was fixed
Compile Swift Module 'Example' (1 sources)
/Users/Karetski/Developer/ExampleSwiftInfiniteCompile/Sources/Example/Example.swift:21:28: error: generic enum type 'Some.Error' is ambiguous without explicit generic parameters when matching value of type 'Error'
} catch Some.Error.some(let instance) {
^
error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/Karetski/Developer/ExampleSwiftInfiniteCompile/.build/debug.yaml main output: