Skip to content

Compiler crash with for...in statement involving parameter packs #67906

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

Closed
xAlien95 opened this issue Aug 12, 2023 · 3 comments · Fixed by #70457
Closed

Compiler crash with for...in statement involving parameter packs #67906

xAlien95 opened this issue Aug 12, 2023 · 3 comments · Fixed by #70457
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions generics Feature: generic declarations and types parameter packs Feature → generics: Parameter packs swift 6.0 type checker Area → compiler: Semantic analysis

Comments

@xAlien95
Copy link
Contributor

Description
Given

struct Variadic<each T>: Sequence {
  typealias Element = Int
  typealias Iterator = [Int].Iterator

  consuming func makeIterator() -> Iterator {
    fatalError()
  }
}

func foo<each T>(_: repeat each T) -> Variadic<repeat each T> {
  .init()
}

the following code is causing a compiler crash, with the error message Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 578 (Full output/stack dump),

for a in foo {
  print(a)
}

and the following one shows the error message Assertion failed: ((!replacement || replacement->hasError() || gp->isParameterPack() == replacement->is<PackType>()) && "replacement for pack parameter must be a pack type"), function operator(), file SubstitutionMap.cpp, line 237.

for a in foo() {
  print(a)
}

Steps to reproduce
Build the script with the latest Swift development snapshot.

Expected behavior
The compiler shouldn't crash.

Environment

  • Swift compiler version info: swift-DEVELOPMENT-SNAPSHOT-2023-08-09-a.xctoolchain, Apple Swift version 5.9-dev (LLVM 79013835e88ccd5, Swift cda0fd4c84d72a9)
  • Xcode version info: Xcode 14.2, Build version 14C18
  • Deployment target: macOS 12.6.8 (21G725)

Additional context
The script compiles if you use an intermediate variable:

let s = foo()

for a in s {
  print(a)
}
@xAlien95 xAlien95 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Aug 12, 2023
@simanerush simanerush added type checker Area → compiler: Semantic analysis crash Bug: A crash, i.e., an abnormal termination of software parameter packs Feature → generics: Parameter packs assertion failure Bug → crash: An assertion failure labels Dec 6, 2023
@simanerush simanerush self-assigned this Dec 6, 2023
@AnthonyLatsis AnthonyLatsis added generics Feature: generic declarations and types for-in loops Feature: for-in loops statements Feature: statements compiler The Swift compiler itself swift 6.0 and removed triage needed This issue needs more specific labels labels Dec 7, 2023
@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Dec 7, 2023

These are two separate bugs. We should open a second issue for either of them.

Reduced test case for crash 1:

struct S<each T> {}
func foo<each T>(_: S<repeat each T>) {}
let _ = foo()

Reduced test case for crash 2:

protocol P {}
struct S<each T>: P {}
func test<T: P>(_: T) {}
test(S())

@simanerush simanerush removed their assignment Dec 7, 2023
@simanerush simanerush removed the for-in loops Feature: for-in loops label Dec 7, 2023
slavapestov added a commit to slavapestov/swift that referenced this issue Dec 14, 2023
slavapestov added a commit to slavapestov/swift that referenced this issue Jan 3, 2024
slavapestov added a commit to slavapestov/swift that referenced this issue Jan 9, 2024
slavapestov added a commit to slavapestov/swift that referenced this issue Jan 9, 2024
@slavapestov
Copy link
Contributor

#70797

@AnthonyLatsis AnthonyLatsis added expressions Feature: expressions types Feature: types and removed statements Feature: statements labels Jan 12, 2024
Catfish-Man pushed a commit to Catfish-Man/swift that referenced this issue Jan 19, 2024
@vanvoorden
Copy link
Contributor

@slavapestov I saw a similar error in #71258.

@AnthonyLatsis AnthonyLatsis removed the types Feature: types label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software expressions Feature: expressions generics Feature: generic declarations and types parameter packs Feature → generics: Parameter packs swift 6.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants