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-11748] Compiler does not reject invalid code #54155

Closed
swift-ci opened this issue Nov 9, 2019 · 4 comments
Closed

[SR-11748] Compiler does not reject invalid code #54155

swift-ci opened this issue Nov 9, 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 run-time crash Bug → crash: Swift code crashed during execution type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 9, 2019

Previous ID SR-11748
Radar rdar://problem/57092093
Original Reporter saeta (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash, TypeChecker
Assignee @CodaFi
Priority Medium

md5: 31af41d148da11ed6947d843fb431c4a

duplicates:

  • SR-6668 Protocol property returning Self triggers "can only be used as a generic constraint" error

Issue Description:

To reproduce:

1. Create foo.swift with the following contents:

struct Foo<T: Numeric> {
  var a: T
  subscript (b: Int) -> Foo { return Foo(a: self.a + 1) }
}

protocol P {
  subscript (b: Int) -> Self { get }
}

extension Foo: P {}

func foo() {
  let bar: [String: P] = ["1": Foo(a: 1)]
  print("Bar: \(bar)")
  let baz = bar.mapValues { $0[2] }
  print("Baz: \(baz)")
}

foo()

Then, run the file by executing swift foo.swift, or alternately, just compile the file by executing swiftc foo.swift.

When running the binary produced by swiftc, I get the following output:

saeta-macbookpro2:foo saeta$ ./foo 
Bar: ["1": foo.Foo<Swift.Int>(a: 1)]
Segmentation fault: 11

When running the file with swift I get the following output:

saeta-macbookpro2:foo saeta$ swift foo.swift 
Bar: ["1": foo.Foo<Swift.Int>(a: 1)]
Stack dump:
0.  Program arguments: /Users/saeta/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret foo.swift -enable-objc-interop -sdk /Users/saeta/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name foo 
0  swift                    0x000000010eb90c83 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010eb90456 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff646feb5d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000002 _sigtramp + 2609910978
4  libswiftCore.dylib       0x00007fff63cf3a33 $ss17_NativeDictionaryV9mapValuesyAByxqd__Gqd__q_KXEKlF + 851
5  libswiftCore.dylib       0x00007fff63cd366b $sSD9mapValuesySDyxqd__Gqd__q_KXEKlF + 171
6  libswiftCore.dylib       0x000000011120a4fd $sSD9mapValuesySDyxqd__Gqd__q_KXEKlF + 2907926333
7  libswiftCore.dylib       0x000000011120a01c $sSD9mapValuesySDyxqd__Gqd__q_KXEKlF + 2907925084
8  swift                    0x000000010a80c2bd llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 365
9  swift                    0x000000010a813272 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1090
10 swift                    0x000000010a7e70b9 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 45977
11 swift                    0x000000010a7d8474 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6868
12 swift                    0x000000010a766fb3 main + 1219
13 libdyld.dylib            0x00007fff645133d5 start + 1
14 libdyld.dylib            0x000000000000000a start + 2611924022
Segmentation fault: 11

I believe the right behavior is to reject the program at compile time, as protocol P can no longer be used as an existential type, due to the use of Self as a return value of the subscript.

@beccadax
Copy link
Contributor

@swift-ci create

@theblixguy
Copy link
Collaborator

On master:

Assertion failed: (indResultTy == indirectResultAddrs[resultIdx++]->getType()), function emitRawApply, file /Users/suyashsrijan/Documents/swift-src/swift/lib/SILGen/SILGenApply.cpp, line 1735.
Stack dump:

@slavapestov
Copy link
Member

This should just work; https://bugs.swift.org/browse/SR-6668 is the bug asking to lift the restriction on properties, so I'm going to combine the two.

@CodaFi
Copy link
Member

CodaFi commented Mar 5, 2020

#30221

@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 run-time crash Bug → crash: Swift code crashed during execution type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

6 participants