Skip to content

[cxx-interop] Fix assertion failure when looking up C++ operators #59345

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

Merged
merged 1 commit into from
Jun 9, 2022

Conversation

egorzhdan
Copy link
Contributor

Previously when looking up a C++ operator (e.g. ==), ClangImporter::Implementation::lookupValue returned a Swift function with a generated name (e.g. func __operatorEqualEqual), while the caller expected the result to be a Swift operator (e.g. func ==).

This change makes sure that we're returning a synthesized Swift operator when looking for a C++ operator.

This fixes an assertion failure in the typechecker:

swift-frontend: /home/build-user/swift/lib/Sema/ConstraintSystem.cpp:1454: std::pair<Type, Type> swift::constraints::ConstraintSystem::getTypeOfReference(swift::ValueDecl *, swift::FunctionRefKind, swift::constraints::ConstraintLocatorBuilder, swift::DeclContext *): Assertion `func->isOperator() && "Lookup should only find operators"' failed.

Previously when looking up a C++ operator (e.g. `==`), `ClangImporter::Implementation::lookupValue` returned a Swift function with a generated name (e.g. `func __operatorEqualEqual`), while the caller expected the result to be a Swift operator (e.g. `func ==`).

This change makes sure that we're returning a synthesized Swift operator when looking for a C++ operator.

This fixes an assertion failure in the typechecker:
```
swift-frontend: /home/build-user/swift/lib/Sema/ConstraintSystem.cpp:1454: std::pair<Type, Type> swift::constraints::ConstraintSystem::getTypeOfReference(swift::ValueDecl *, swift::FunctionRefKind, swift::constraints::ConstraintLocatorBuilder, swift::DeclContext *): Assertion `func->isOperator() && "Lookup should only find operators"' failed.
```
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jun 9, 2022
@egorzhdan egorzhdan requested review from Huddie and zoecarver June 9, 2022 18:25
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

This is a requirement for #58699.

@egorzhdan
Copy link
Contributor Author

Merging to unblock other work, happy to discuss post-merge.

Copy link
Contributor

@Huddie Huddie left a comment

Choose a reason for hiding this comment

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

This is really nice! Great commenting! 👍 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants