Files
swift-mirror/test/Parse/ConditionalCompilation/decl_parse_errors.swift
Rintaro Ishizaki f70d2d9e1c [Parse] Skip ahead if seeing any error while parsing list.
If we found any error in a list, in most cases, we cannot expect that the
following tokens could construct a valid element. Skip them, instead of trying
to parse them as the next element. This significally reduces bogus diagnostics.

Bailout if seeing tok::eof or token that can never start a element, after
parsing an element. This silences superfluous "expected ',' separator" error,
or misleading expected declaration error. What we should emit is
"expected ')' in expression list, or "expected '}' in struct".
2016-10-09 04:05:07 +09:00

41 lines
1.1 KiB
Swift

// RUN: %target-parse-verify-swift
public
#if FOO // expected-error {{expected declaration}}
var val1: Int = 0
#else
var val1: UInt = 1
#endif
struct S2 { // expected-note {{in declaration of 'S2'}}
@available(*, deprecated)
#if FOO // expected-error {{expected declaration}}
func fn1() {}
#endif
}
// expected-error@+2 {{expected declaration}}
private
#sourceLocation(file: "test.swift", line: 1)
var val2: Int = 0
#sourceLocation()
// expected-error@+3 {{expected declaration}}
// expected-error@+2 {{#line directive was renamed to #sourceLocation}}
lazy
#line 12 "test.swift"
var val3: Int = 0;
#line
class C { // expected-note 2 {{in declaration of 'C'}} expected-note {{to match this opening '{'}}
#if os(iOS)
func foo() {}
} // expected-error{{expected declaration}} expected-error{{expected #else or #endif at end of conditional compilation block}}
#else
func bar() {}
func baz() {}
} // expected-error{{expected declaration}} expected-error{{expected #else or #endif at end of conditional compilation block}}
#endif
// expected-error@+1{{expected '}' in class}}