|
| 1 | +# Syntax errors |
| 2 | + |
| 3 | +Test cases to ensure that red knot does not panic if there are syntax errors in the source code. |
| 4 | + |
| 5 | +## Keyword as identifiers |
| 6 | + |
| 7 | +When keywords are used as identifiers, the parser recovers from this syntax error by emitting an |
| 8 | +error and including the text value of the keyword to create the `Identifier` node. |
| 9 | + |
| 10 | +### Name expression |
| 11 | + |
| 12 | +```py |
| 13 | +# error: [invalid-syntax] |
| 14 | +pass = 1 |
| 15 | + |
| 16 | +# error: [invalid-syntax] |
| 17 | +# error: [invalid-syntax] |
| 18 | +type pass = 1 |
| 19 | + |
| 20 | +# error: [invalid-syntax] |
| 21 | +# error: [invalid-syntax] |
| 22 | +# error: [invalid-syntax] |
| 23 | +# error: [invalid-syntax] |
| 24 | +# error: [invalid-syntax] |
| 25 | +def True(for): |
| 26 | + # error: [invalid-syntax] |
| 27 | + pass |
| 28 | + |
| 29 | +# TODO: Why is there two diagnostics for the same error? |
| 30 | + |
| 31 | +# error: [invalid-syntax] |
| 32 | +# error: [invalid-syntax] |
| 33 | +# error: [invalid-syntax] |
| 34 | +# error: [unresolved-reference] "Name `pass` used when not defined" |
| 35 | +# error: [unresolved-reference] "Name `pass` used when not defined" |
| 36 | +for while in pass: |
| 37 | + pass |
| 38 | + |
| 39 | +# error: [invalid-syntax] |
| 40 | +# error: [unresolved-reference] "Name `in` used when not defined" |
| 41 | +while in: |
| 42 | + pass |
| 43 | + |
| 44 | +# error: [invalid-syntax] |
| 45 | +# error: [invalid-syntax] |
| 46 | +# error: [unresolved-reference] "Name `match` used when not defined" |
| 47 | +match while: |
| 48 | + # error: [invalid-syntax] |
| 49 | + # error: [invalid-syntax] |
| 50 | + # error: [invalid-syntax] |
| 51 | + # error: [unresolved-reference] "Name `case` used when not defined" |
| 52 | + case in: |
| 53 | + # error: [invalid-syntax] |
| 54 | + # error: [invalid-syntax] |
| 55 | + pass |
| 56 | +``` |
| 57 | + |
| 58 | +### Attribute expression |
| 59 | + |
| 60 | +```py |
| 61 | +# TODO: Why is there two diagnostics for the same error? |
| 62 | +# TODO: Check when support for attribute expressions is added |
| 63 | + |
| 64 | +# error: [invalid-syntax] |
| 65 | +# error: [unresolved-reference] "Name `foo` used when not defined" |
| 66 | +# error: [unresolved-reference] "Name `foo` used when not defined" |
| 67 | +for x in foo.pass: |
| 68 | + pass |
| 69 | +``` |
0 commit comments