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-11386] func callAsFunction crasher regarding missing conditionally conformances #53787

Closed
dan-zheng opened this issue Aug 28, 2019 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-11386
Radar None
Original Reporter @dan-zheng
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee @hamishknight
Priority Medium

md5: 2d184545d99edc1f1032724a7ca862df

Issue Description:

Reproducer:

class C<T> {}
protocol P {}
extension C where T: P {
  func callAsFunction(t: T) {}
}

let c = C<Int>()
// Expected behavior: error message because `c` is not callable.
// Since `Int` does not conform to `P`, `callAsFunction` should not be found via name lookup.
c(42)

Crashes:

$ swift sr-11386.swift
Stack dump:
0.  Program arguments: /Users/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64/bin/swift -frontend -interpret sr-11386.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name main
1.  Swift version 5.1-dev (LLVM 200186e28b, Swift cebbd6335d)
2.  While type-checking statement at [sr-11386.swift:8:1 - line:8:5] RangeText="c(42"
3.  While type-checking expression at [sr-11386.swift:8:1 - line:8:5] RangeText="c(42"
0  swift                    0x000000010fbbd245 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010fbbc288 llvm::sys::RunSignalHandlers() + 248
2  swift                    0x000000010fbbd838 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6b1abb5d _sigtramp + 29
4  libsystem_platform.dylib 0xfffffffffffffff8 _sigtramp + 2498053304
5  swift                    0x000000010c900feb swift::constraints::MissingConformance::diagnose(swift::Expr*, bool) const + 123
6  swift                    0x000000010c8716d4 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&)::DiagnosticWalker::diagnose(swift::Expr*) + 276
7  swift                    0x000000010c870e77 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&)::DiagnosticWalker::walkToExprPost(swift::Expr*) + 23
8  swift                    0x000000010ccad973 swift::Expr::walk(swift::ASTWalker&) + 115
9  swift                    0x000000010c86d7f2 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&) + 530
10 swift                    0x000000010c86d94d swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 141
11 swift                    0x000000010c9a9843 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1107
12 swift                    0x000000010c9a93df swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 63
13 swift                    0x000000010ca41fca swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 602
14 swift                    0x000000010ca40c18 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
15 swift                    0x000000010ca40d0e swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 174

func callAsFunction lookup should be careful about conditional conformances.

@theblixguy
Copy link
Collaborator

Hmm seems like its crashing because getRequirementDC() and getGenericContext() return nullptr (there's a bunch of new asserts in

RequirementFailure's initializer). I'll try to take a look tomorrow.

(without those asserts, we do end up printing the right diagnostic, but still crash later. Anyway, we ought to have both the requirement DC and generic context in this case, so something else is going wrong, perhaps when the fix is being created).

@theblixguy
Copy link
Collaborator

Revisiting this... so obviously we generate the right diagnostics if callAsFunction is directly called, but not when it's implicitly called. I think to fix this what we need to do is to follow what @xedin suggested in the PR for this feature. I am not fully clear as to how its supposed to work, but so far I have added an ImplicitCall path element, so locator for the applicable function is implicit call -> apply function:

auto applicableFnLoc = getConstraintLocator(anchor, {ConstraintLocator::ImplicitCall, ConstraintLocator::ApplyFunction}, locator.getSummaryFlags());

@xedin Do we need to change matchCallArguments as well?

@xedin
Copy link
Member

xedin commented Sep 20, 2019

@theblixguy I don't think we need to modify anything there, just a new path element to identify that this was an implicit call and teach diagnostics that something like this might happen e.g. requirement failure, argument mismatches, re-labeling etc. Also `getChoiceFor` has to be able to retrieve overload choice selected for `callAsFunction`.

@hamishknight
Copy link
Collaborator

Fixed by #28519

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants