Skip to content

[C++ interop] Function from other Swift module not found if it returns C++ template class #82297

Open
@AnthonyLatsis

Description

@AnthonyLatsis

Description

No response

Reproduction

// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/include)
// RUN: split-file %s %t
//
// RUN: %target-swift-frontend -emit-module -module-name a -emit-module-path %t/include/a.swiftmodule %t/a.swift -cxx-interoperability-mode=default -I %t/include
// RUN: %target-swift-frontend -typecheck %t/b.swift -cxx-interoperability-mode=default -I %t/include

//--- include/module.modulemap
module cxx {
  header "header.h"
  export *
}

//--- include/header.h
template <typename T> struct Optional {
  T value;
};
using OptionalBool = Optional<bool>;
inline OptionalBool getOptBool() {
  return {true};
}

//--- a.swift
import cxx
public func bar() -> OptionalBool { getOptBool() }

//--- b.swift
import a
import cxx
public func baz() -> Bool { bar().value }
/Users/alatsis/Desktop/swiftlang/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/test-macosx-arm64/Interop/Cxx/Output/bug.swift.tmp/b.swift:3:29: error: cannot find 'bar' in scope; did you mean 'baz'?
1 | import a
2 | import cxx
3 | public func baz() -> Bool { bar().value }
  |             |               `- error: cannot find 'bar' in scope; did you mean 'baz'?
  |             `- note: 'baz' declared here
4 | 

Expected behavior

Success.

Environment

Swift version 6.2-dev (LLVM 8bcf2671393ccfb, Swift 8acde34)

Additional information

No response

Metadata

Metadata

Assignees

Labels

c++ interopFeature: Interoperability with C++c++ to swiftFeature → c++ interop: c++ to swiftcompilerThe Swift compiler itselfgenericsFeature: generic declarations and typesmultiple modulesFlag: An issue whose reproduction requires multiple modulesswift 6.2type checkerArea → compiler: Semantic analysis

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions