| 1 | # LSP Test 3: Diagnostics (Automatic) |
| 2 | # ==================================== |
| 3 | # |
| 4 | # Instructions: |
| 5 | # 1. Diagnostics appear automatically as you edit |
| 6 | # 2. Look for underlined/highlighted code indicating errors or warnings |
| 7 | # 3. Errors and warnings should appear in the editor |
| 8 | # 4. The status bar may show diagnostic counts |
| 9 | # |
| 10 | # This file contains intentional errors for testing: |
| 11 | |
| 12 | # Error 1: Undefined variable |
| 13 | result = undefined_variable + 10 |
| 14 | |
| 15 | # Error 2: Type mismatch (if using type checker) |
| 16 | def add_numbers(a: int, b: int) -> int: |
| 17 | return a + b |
| 18 | |
| 19 | wrong_type = add_numbers("hello", "world") |
| 20 | |
| 21 | # Error 3: Import error |
| 22 | from nonexistent_module import something |
| 23 | |
| 24 | # Error 4: Syntax-like issues |
| 25 | def broken_function(x, y) # Missing colon - uncomment to test |
| 26 | return x + y |
| 27 | |
| 28 | # Error 5: Unused variable (warning) |
| 29 | unused_var = 42 |
| 30 | |
| 31 | # Error 6: Undefined name in expression |
| 32 | value = some_undefined_function() |
| 33 | |
| 34 | # Error 7: Wrong number of arguments |
| 35 | def takes_two(a, b): |
| 36 | return a + b |
| 37 | |
| 38 | takes_two(1) # Missing argument |
| 39 | takes_two(1, 2, 3) # Too many arguments |
| 40 | |
| 41 | # Error 8: Attribute error |
| 42 | my_string = "hello" |
| 43 | my_string.nonexistent_method() |
| 44 | |
| 45 | # Error 9: Invalid operation |
| 46 | result = "string" + 42 |
| 47 | |
| 48 | # Error 10: Redefinition (warning in some linters) |
| 49 | def duplicate(): |
| 50 | pass |
| 51 | |
| 52 | def duplicate(): # Redefined function |
| 53 | pass |
| 54 | |
| 55 | |
| 56 | # Working code for comparison - this should have no errors: |
| 57 | def working_function(name: str) -> str: |
| 58 | """This function works correctly.""" |
| 59 | return f"Hello, {name}!" |
| 60 | |
| 61 | greeting = working_function("World") |
| 62 | print(greeting) |