Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,7 @@ func isCastSupportedInEmbeddedSwift(from sourceType: Type,
return false
}

// Tuple?
if !destType.isStruct && !destType.isClass && !destType.isEnum {
if !destType.isStruct && !destType.isClass && !destType.isEnum && !destType.isTuple {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment listing which types are not supported here? Function types? Also why aren't they supported when tuples are supported? Tuples can have arbitrary element types, including function types, in them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are not tests yet so only the types listed here are "supported" (at this time).

When I add metadata generation for function types they will be added.

The intend is to gradually add more types.

Foreign types don't work either. And the two types I have mentioned I am sure are not a complete list of unsupported types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tuple of function types works because we know how to generate metadata for tuples.

The code to generate function type metadata I have not added yet.

return false
}

Expand Down
15 changes: 15 additions & 0 deletions test/embedded/existential.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ func test11(_ p: any Any) {
let c = p as! SubClass
c.foo()
}

func test12(_ p: any Any) {
print("test any as! (Int, Int, Int, Int)")
if let c = p as? (Int, Int, Int, Int) {
print("success")
print("tuple: \(c.0)")
} else {
print("cast failed")
}
}

@main
struct Main {
static func main() {
Expand Down Expand Up @@ -372,5 +383,9 @@ struct Main {
// OUTPUT: SubClass.foo
// OUTPUT: BaseClass.deinit
// OUTPUT-NOT: deinit
test12((0, 1, 2, 3))
// OUTPUT: test any as! (Int, Int, Int, Int)
// OUTPUT: success
// OUTPUT: tuple: 0
}
}