Skip to content

Improve error message for undefined user type #1993

Closed
@certik

Description

@certik

This:

def check_re_range_alternatives(
        alts : list[ReRange],
        char : str) -> bool:
    result : bool = False
    rr : ReRange
    for rr in alts:
        if check_re_range(rr, char):
            result = True
            break
    return result

gives:

$ lpython a.py 
semantic error: Unsupported type annotation: ReRange
 --> a.py:2:21
  |
2 |         alts : list[ReRange],
  |                     ^^^^^^^ 

But rather the error message should be:

semantic error: The type `ReRange` is not declared

or

semantic error: Unknown type `ReRange`

I think I like the second more.

Regarding "Unsupported type annotation: ReRange", that should be emitted for things like from typing import List. If you just do List[i32] without importing it from anywhere, then I think it should just say Unknown type List, and we can provide a "hint: did you mean list?"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions