Skip to content

[SR-13018] Type constraints are not honored when invoking method #55463

@mbrandonw

Description

@mbrandonw
Previous ID SR-13018
Radar rdar://problem/64953119
Original Reporter @mbrandonw
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash
Assignee @slavapestov
Priority Medium

md5: 2c03afa2034e8d179cd73102ecf6a551

Issue Description:

Consider the following method:

struct T<A> {
  func run<C>(_ c: C) where C: Collection, C.SubSequence == A {
    print(c[...] as! A)
  }
}

This should restrict the collection passed into `run` to be such that its subsequence matches the generic A.

For example, these following compile just fine:

// These should compile ✅
T<Substring>().run("")
T<Data>().run(Data())

However, there seem to be some situations where we can pass in a collection that does not match this constraint and yet it still compiles, and hence crashes at runtime:

// These should not but do⁉️
T<Substring>().run(Data())
T<Data>().run("")

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during execution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions