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-38] "protocol can only be used as a generic constraint" errors reported twice #42661

Closed
lilyball mannequin opened this issue Dec 4, 2015 · 1 comment
Closed

[SR-38] "protocol can only be used as a generic constraint" errors reported twice #42661

lilyball mannequin opened this issue Dec 4, 2015 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Dec 4, 2015

Previous ID SR-38
Radar None
Original Reporter @lilyball
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift e8a15c6)
Target: x86_64-apple-macosx10.9
Compiled with the default build-script settings

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @gregomni
Priority Medium

md5: d13102ac8bfee811237d0ecbc6545377

Issue Description:

The code snippet from SR-8 illustrates a curious bug:

protocol P {
    typealias T
    var env: T { get }
    func f(a: Int);
}

struct IgnoreInt: P {
    typealias T = Int
    var env: T
    func f(a: Int) { }
}

class IntBox {
    var value: Int
    init(value: Int) { self.value = value; }
}

struct AssignIntBox: P {
    typealias T = IntBox
    var env: T
    func f(a: Int) { env.value = a }
}

var a: P = IgnoreInt(env: 0)
var b: P = AssignIntBox(env: IntBox(value: 0))
b = a
b.f(1);

In Swift 2.1 (swiftlang-700.1.101.6), this correctly emits two errors:

foo.swift:24:8: error: protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
var a: P = IgnoreInt(env: 0)
       ^
foo.swift:25:8: error: protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
var b: P = AssignIntBox(env: IntBox(value: 0))
       ^

Current tip of master emits each error twice, once for the protocol type, and then again for the variable:

foo.swift:24:8: error: protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
var a: P = IgnoreInt(env: 0)
       ^
foo.swift:24:5: error: protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
var a: P = IgnoreInt(env: 0)
    ^
foo.swift:25:8: error: protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
var b: P = AssignIntBox(env: IntBox(value: 0))
       ^
foo.swift:25:5: error: protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
var b: P = AssignIntBox(env: IntBox(value: 0))
    ^
@gregomni
Copy link
Collaborator

gregomni commented Feb 4, 2016

This got fixed in #1069

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant