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-7466] Compiler crash when referencing instance member as default parameter #50009

Closed
swift-ci opened this issue Apr 18, 2018 · 1 comment
Closed

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Apr 18, 2018

Previous ID SR-7466
Radar None
Original Reporter allewun (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 4.0, Xcode 9.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: d8fe33131133499279230b868d053712

duplicates:

  • SR-2189 Nested function with local default value crashes

relates to:

  • SR-2189 Nested function with local default value crashes

Issue Description:

Swift doesn't allow using instance members as default parameters for methods.

This emits a compiler warning "Cannot use instance member 'humanLifespan' as default parameter":

class Person {
    let humanLifespan: Int = 200
    
    func _isAlive(at age: Int, maxAge: Int = humanLifespan) -> Bool {
        return age <= maxAge
    }
}

But if the function is nested in another function, I get a compiler crash instead:

class Person {
    let humanLifespan: Int = 200
    
    func isAlive(at age: Int) -> Bool {
        func _isAlive(at age: Int, maxAge: Int = humanLifespan) -> Bool {
            return age <= maxAge
        }
        
        return _isAlive(at: age)
    }
}

Command failed due to signal: Abort trap: 6

Global is external, but doesn't have external or weak linkage!
i8* ()* @_T04test6PersonC7isAliveSbSi2at_tF4selfL_ACfau
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken module found, compilation aborted!
0  swift                    0x000000010667836a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x00000001066777a6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff994f1b3a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000004 _sigtramp + 1722868964
4  libsystem_c.dylib        0x00007fff99376420 abort + 129
5  swift                    0x0000000102fd1a57 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_0::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 551
6  swift                    0x0000000106635adb llvm::report_fatal_error(llvm::Twine const&, bool) + 571
7  swift                    0x000000010663589a llvm::report_fatal_error(char const*, bool) + 42
8  swift                    0x000000010660bd34 (anonymous namespace)::VerifierLegacyPass::doFinalization(llvm::Module&) + 260
9  swift                    0x00000001065b8985 llvm::FPPassManager::doFinalization(llvm::Module&) + 53
10 swift                    0x00000001065bdbd7 llvm::legacy::FunctionPassManagerImpl::doFinalization(llvm::Module&) + 71
11 swift                    0x00000001031501e5 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 5045
12 swift                    0x0000000102fd64ce performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 19054
13 swift                    0x0000000102fd01f4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
14 swift                    0x0000000102f84e78 main + 12248
15 libdyld.dylib            0x00007fff992e2235 start + 1
16 libdyld.dylib            0x0000000000000043 start + 1725029903
@belkadan
Copy link
Contributor

@belkadan belkadan commented Apr 18, 2018

@slavapestov, should we call this the same as SR-2189, or is it worth keeping separate?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants