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-4665] Type from unimported module gets exposed when returned in function from other file #47242

Open
louisdh opened this issue Apr 21, 2017 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself feature A feature request or implementation

Comments

@louisdh
Copy link
Contributor

louisdh commented Apr 21, 2017

Previous ID SR-4665
Radar None
Original Reporter @louisdh
Type Bug
Environment

Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, LanguageFeatureRequest
Assignee @belkadan
Priority Medium

md5: 8276573cf5b3264bca7dd66688bdd221

Issue Description:

Consider the following example with 2 modules and 3 files.

Module A: File1.swift & File2.swift
File1.swift:

import Foundation

func foo() {
    
     let t1 = SomeModuleType() // error, as expected
    
     let t2 = getSomeModuleType() // compiles, expected error: "Need to import module B to use this function's return type"
     print(t2.printMe()) // prints "Hello from unimported module!"
    
}

File2.swift:

import Foundation
import B

func getSomeModuleType() -> SomeModuleType {
     return SomeModuleType()
}

Module B: SomeModuleType.swift

public class SomeModuleType {
    
     public init() { }
    
     public func printMe() {
          print("Hello from unimported module!")
    }
    
}

I'm not sure if this is by design, but it certainly feels like a bug to me that a type from an unimported module becomes "available" (e.g. allows to call any methods on it).

@belkadan
Copy link
Contributor

It's "expected behavior" but certainly a little surprising. I want to clean some of this up in the model.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

2 participants