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-524] AnyObject unresolved dot expr does not work across files in the same module #43141

Closed
swift-ci opened this issue Jan 12, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-524
Radar rdar://problem/20217221
Original Reporter emanuel (JIRA User)
Type Bug
Environment

Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 6e4f61c)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: fbc1db1ee131fe26d1687a21de8dd692

relates to:

  • SR-525 AnyObject unresolved dot expr fails oddly and intermittently

Issue Description:

Description:

If a property is defined in another file in the current module, the compiler appears to be unwilling to resolve an unresolved dot expression on an AnyObject instance to refer to that property.

Sample Case:

File main.swift

testObject.property

File Bug.swift

import Foundation
public class Foo : NSObject {
  public var property : Int = 33
}

let testObject : AnyObject = Foo()

Run command, with appropriate SDKROOT set.

swiftc main.swift Bug.swift

Expected result: compilation with no errors.

Actual result:

main.swift:2:1: error: value of type 'AnyObject' has no member 'property'
testObject.property
^~~~~~~~~~ ~~~~~~~~

If all the code is stored in the same file, this works okay.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis
Copy link
Collaborator

Interesting, this is not a bug. Dynamic lookup will not find Foo.property unless you expose it to Objective-C with @objc—inheriting from NSObject does not count. The property it finds when you place everything in a single file is Foundation.Stream.property(forKey:), and the reason this fails in the original example is because you forgot to import Foundation in main.swift.

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
Projects
None yet
Development

No branches or pull requests

2 participants