Skip to content

Better error message for 'class func/var' usage in protocols (part 2) #17053

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/AST/DiagnosticsCommon.def
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ ERROR(super_not_in_class_method,none,

ERROR(class_func_not_in_class,none,
"class methods are only allowed within classes; "
"use 'static' to declare a%select{| requirement fulfilled by either a class or}0 static method", (bool))
"use 'static' to declare a %select{static|requirement fulfilled by either a static or class}0 method", (bool))
ERROR(class_var_not_in_class,none,
"class properties are only allowed within classes; "
"use 'static' to declare a%select{| requirement fulfilled by either a class or}0 static property", (bool))
"use 'static' to declare a %select{static|requirement fulfilled by either a static or class}0 property", (bool))

// FIXME: Used by both the parser and the type-checker.
ERROR(func_decl_without_brace,PointsToFirstBadToken,
Expand Down
2 changes: 1 addition & 1 deletion test/decl/func/static_func.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protocol P { // expected-note{{extended type declared here}}
static func f2()
static func f3() {} // expected-error {{protocol methods must not have bodies}}
static final func f4() // expected-error {{only classes and class members may be marked with 'final'}}
class func f5() // expected-error {{class methods are only allowed within classes; use 'static' to declare a requirement fulfilled by either a class or static method}} {{3-8=static}}
class func f5() // expected-error {{class methods are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class method}} {{3-8=static}}
}

extension P {
Expand Down
4 changes: 2 additions & 2 deletions test/decl/var/static_var.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ extension C {
protocol P { // expected-note{{did you mean 'P'?}} expected-note{{extended type declared here}}
// Both `static` and `class` property requirements are equivalent in protocols rdar://problem/17198298
static var v1: Int { get }
class var v2: Int { get } // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a class or static property}} {{3-8=static}}
class var v2: Int { get } // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}}
static final var v3: Int { get } // expected-error {{only classes and class members may be marked with 'final'}}

static let l1: Int // expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}}
class let l2: Int // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a class or static property}} {{3-8=static}} expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}}
class let l2: Int // expected-error {{class properties are only allowed within classes; use 'static' to declare a requirement fulfilled by either a static or class property}} {{3-8=static}} expected-error {{immutable property requirement must be declared as 'var' with a '{ get }' specifier}}
}

extension P {
Expand Down