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-8447] Assertion hit in use-before-declaration case #50968

Closed
rintaro mannequin opened this issue Aug 2, 2018 · 3 comments
Closed

[SR-8447] Assertion hit in use-before-declaration case #50968

rintaro mannequin opened this issue Aug 2, 2018 · 3 comments
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

Comments

@rintaro
Copy link
Mannequin

rintaro mannequin commented Aug 2, 2018

Previous ID SR-8447
Radar None
Original Reporter @rintaro
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 9d49b5e717c9a1b7c0cd5fa351974705

duplicates:

  • SR-7517 Assertion failed: (hasInterfaceType() && "No interface type was set")

Issue Description:

func test() {
  let obj = foo
  let _ = obj.prop, foo
}

current master:

Assertion failed: (D->hasValidSignature()), function getType, file /Users/rintaro/Repositories/swift-oss/swift/lib/Sema/ConstraintSystem.h, line 1661.
0  swift                    0x000000010fc12b78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010fc11ae6 llvm::sys::RunSignalHandlers() + 198
2  swift                    0x000000010fc13202 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff7580ff5a _sigtramp + 26
4  libsystem_platform.dylib 0x00000001180cf650 _sigtramp + 2727081744
5  libsystem_c.dylib        0x00007fff755ad1ae abort + 127
6  libsystem_c.dylib        0x00007fff755751ac basename_r + 0
7  swift                    0x000000010cfbe169 swift::constraints::ConstraintSystem::getType(swift::VarDecl const*, bool) const + 137
8  swift                    0x000000010cfb8100 swift::TypeChecker::getUnopenedTypeOfReference(swift::VarDecl*, swift::Type, swift::DeclContext*, llvm::function_ref<swift::Type (swift::VarDecl*)>, swift::DeclRefExpr const*, bool) + 32
9  swift                    0x000000010cfb88e5 swift::constraints::ConstraintSystem::getTypeOfReference(swift::ValueDecl*, swift::FunctionRefKind, swift::constraints::ConstraintLocatorBuilder, swift::DeclContext*, swift::DeclRefExpr const*) + 389
10 swift                    0x000000010cfbafe1 swift::constraints::ConstraintSystem::resolveOverload(swift::constraints::ConstraintLocator*, swift::Type, swift::constraints::OverloadChoice, swift::DeclContext*) + 561
11 swift                    0x000000010cf50fb6 swift::ASTVisitor<(anonymous namespace)::ConstraintGenerator, swift::Type, void, void, void, void, void>::visit(swift::Expr*) + 18502
12 swift                    0x000000010cf54fbf (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 415
13 swift                    0x000000010d3308f2 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 178
14 swift                    0x000000010d3301e4 swift::Expr::walk(swift::ASTWalker&) + 84
15 swift                    0x000000010cf4b379 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 409
16 swift                    0x000000010cf83837 swift::constraints::ConstraintSystem::solveImpl(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 471
17 swift                    0x000000010cf833df swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 31
18 swift                    0x000000010d01adad swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 845
19 swift                    0x000000010d0224c7 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 423
20 swift                    0x000000010d022768 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 216
21 swift                    0x000000010d03b122 validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 786
22 swift                    0x000000010d036f73 swift::TypeChecker::validateDecl(swift::ValueDecl*) + 2483
23 swift                    0x000000010d01a532 findNonMembers(swift::TypeChecker&, llvm::ArrayRef<swift::LookupResultEntry>, swift::DeclRefKind, bool, llvm::SmallVectorImpl<swift::ValueDecl*>&, llvm::function_ref<bool (swift::ValueDecl*)>) + 194
24 swift                    0x000000010d018426 swift::TypeChecker::resolveDeclRefExpr(swift::UnresolvedDeclRefExpr*, swift::DeclContext*) + 630
25 swift                    0x000000010d02771b (anonymous namespace)::PreCheckExpression::walkToExprPre(swift::Expr*) + 395
26 swift                    0x000000010d3301ae swift::Expr::walk(swift::ASTWalker&) + 30
27 swift                    0x000000010d01ab78 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 280
28 swift                    0x000000010d0224c7 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 423
29 swift                    0x000000010d022768 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 216
30 swift                    0x000000010d03b122 validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 786
31 swift                    0x000000010d033252 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 882
32 swift                    0x000000010d032ed6 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 38
33 swift                    0x000000010d0aacea swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 618
34 swift                    0x000000010d0a9bb5 (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 85
35 swift                    0x000000010d0a9000 swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 288
36 swift                    0x000000010d0a9ad1 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 337
37 swift                    0x000000010d0c9db5 typeCheckFunctionsAndExternalDecls(swift::SourceFile&, swift::TypeChecker&) + 325
38 swift                    0x000000010d0caf8b swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 2187
39 swift                    0x000000010cd03028 swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t, swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 472
40 swift                    0x000000010cd01beb swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 667
41 swift                    0x000000010cd01019 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 505
42 swift                    0x000000010c0e4d9e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1278
43 swift                    0x000000010c0e382f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2943
44 swift                    0x000000010c097bd8 main + 1128
45 libdyld.dylib            0x00007fff75501015 start + 1
46 libdyld.dylib            0x000000000000000a start + 2326786038
Stack dump:
0.  Program arguments: /Users/rintaro/Repositories/swift-oss/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -interpret test.swift -enable-objc-interop -sdk /Applications/Xcode/External/10L221o/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name test 
1.  While type-checking 'test()' at test.swift:1:1
2.  While type-checking statement at [test.swift:1:13 - line:4:1] RangeText="{
  let obj = foo
  let _ = obj.prop, foo
}"
3.  While type-checking declaration 0x7fe0b107a980 at test.swift:2:3
4.  While type-checking expression at [test.swift:2:13 - line:2:13] RangeText="f"
5.  While validating 'foo' at test.swift:3:21
6.  While type-checking expression at [test.swift:3:11 - line:3:15] RangeText="obj.p"
Abort trap: 6

(Xcode 10 beta5)
Apple Swift version 4.2 (swiftlang-1000.0.32.1 clang-1000.10.39)

test.swift:3:11: error: type of expression is ambiguous without more context
  let _ = obj.prop, foo
          ^~~
test.swift:3:21: error: type annotation missing in pattern
  let _ = obj.prop, foo
                    ^
test.swift:2:13: error: use of local variable 'foo' before its declaration
  let obj = foo
            ^
test.swift:3:21: note: 'foo' declared here
  let _ = obj.prop, foo
                    ^
@rintaro
Copy link
Mannequin Author

rintaro mannequin commented Aug 2, 2018

#18466
This is essentially a circular case.
(pattern-binding-decl "let obj =") -> (expr foo) -> (vardecl foo) -> (pattern-binding-decl "let _ =") -> (expr obj.prop) -> (vardecl obj) -> (pattern-binding-decl "let obj =").

@DougGregor Although my PR fixes this specific crash, I'm not sure my change fixes underlying problem.

@belkadan
Copy link
Contributor

belkadan commented Aug 2, 2018

Is this the same as SR-7517?

@rintaro
Copy link
Mannequin Author

rintaro mannequin commented Aug 3, 2018

Yeah, It looks like the same issue.

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

No branches or pull requests

2 participants