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-12415] 5.2 regression: Overload resolution for dynamicMemberLookup / dynamicCallable type fails #54854

Closed
WFT opened this issue Mar 25, 2020 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 5.2 type checker Area → compiler: Semantic analysis

Comments

@WFT
Copy link

WFT commented Mar 25, 2020

Previous ID SR-12415
Radar rdar://problem/62200969
Original Reporter @WFT
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Environment

Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.3.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.2Regression, TypeChecker
Assignee @WFT
Priority Medium

md5: f003a9c7f901c3a74533ee7961ed78c9

Issue Description:

The following (minimized) example fails to compile in the new 5.2 release, but worked fine in Swift 5.1:

@dynamicCallable
@dynamicMemberLookup
public struct Foo {
    subscript(dynamicMember memberName: String) -> Foo {
        get { return self }
        set { self = newValue }
    }

    func think() -> [Foo] { [self] }
    
    @discardableResult
    func dynamicallyCall(
      withKeywordArguments args:
        KeyValuePairs<String, Int> = [:]
    ) -> Foo {
        return self
    }
}


var f = Foo()
print(f.think(arg: 1)) // error here

In Swift 5.1, this would do a dynamic member lookup to find think, then call it dynamically with [arg:1]. In Swift 5.2, this finds the non-dynamic think method and tries to call that. It doesn't work because that method has no arguments.

The errors output are as follows:

dynamic-error.swift:22:20: error: argument passed to call that takes no arguments
print(f.think(arg: 1))
                   ^

The fact that this used to work is definitely a little odd, but it makes usecases like PythonKit much harder to use. In the code this example came from, Foo was PythonObject and think was a method called filter.

The workaround is to replace the

@beccadax
Copy link
Contributor

@swift-ci create

@xedin
Copy link
Member

xedin commented Apr 30, 2020

This is intentional as mentioned in the proposal - https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md#detailed-design. Dynamic lookup would only be attempted if there are no members in the type with a given name, since there is a `thing` already it's always preferred even if it doesn't match.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 regression swift 5.2 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants