mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Parsing declaration list (e.g. member list of nominal decl) is very
different from comma separated list, because it's elements are separated with
new-line or semi-colon. There's no good reason to consolidate them.
Also, declaration list in 'extension' or inside of decl '#if' didn't
emit diagnostics for consecutive declarations on a line.
class C {
#if true
var value: Int = 42 func foo() {}
#endif
}
extension C {
func bar() {} subscript(i: Int) -> Int {
return 24
}
}
This change consolidates declaration list parsing for
members of nominal decls, extensions, and inside of '#if'.
In addition, removed unnecessary property 'TrailingSemiLoc' from decl.
45 lines
1.4 KiB
Swift
45 lines
1.4 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
struct S {
|
|
var a : Int ;
|
|
func b () {};
|
|
static func c () {};
|
|
}
|
|
|
|
struct SpuriousSemi {
|
|
; // expected-error{{unexpected ';' separator}} {{3-5=}}
|
|
var a : Int ; ; // expected-error{{unexpected ';' separator}} {{17-19=}}
|
|
func b () {};
|
|
; static func c () {}; // expected-error{{unexpected ';' separator}} {{3-5=}}
|
|
;;
|
|
// expected-error @-1 {{unexpected ';' separator}} {{3-4=}}
|
|
// expected-error @-2 {{unexpected ';' separator}} {{4-5=}}
|
|
}
|
|
|
|
class C {
|
|
var a : Int = 10 func aa() {}; // expected-error {{consecutive declarations on a line must be separated by ';'}} {{19-19=;}}
|
|
#if FLAG1
|
|
var aaa: Int = 42 func aaaa() {}; // expected-error {{consecutive declarations on a line must be separated by ';'}} {{20-20=;}}
|
|
#elseif FLAG2
|
|
var aaa: Int = 42 func aaaa() {} // expected-error {{consecutive declarations on a line must be separated by ';'}} {{20-20=;}}
|
|
#else
|
|
var aaa: Int = 42 func aaaa() {} // expected-error {{consecutive declarations on a line must be separated by ';'}} {{20-20=;}}
|
|
#endif
|
|
|
|
func b () {};
|
|
class func c () {};
|
|
}
|
|
|
|
extension S {
|
|
//var a : Int ;
|
|
func bb () {};
|
|
static func cc () {};
|
|
func dd() {} subscript(i: Int) -> Int { return 1 } // expected-error {{consecutive declarations on a line must be separated by ';'}} {{15-15=;}}
|
|
}
|
|
|
|
protocol P {
|
|
var a : Int { get };
|
|
func b ();
|
|
static func c ();
|
|
}
|