Skip to content

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

@xAlien95

Description

@xAlien95

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionsgenericsFeature: generic declarations and typesparameter packsFeature → generics: Parameter packsswift 6.0type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions