vyper --version): 0.1.0b11The following doesn't compile:
@public
def foo(b: bytes[65]) -> bytes32:
return convert(b[:32], bytes32)
and gives the following error message, which isn't helpful
...
vyper/ast_utils.py in _build_vyper_ast_list(source_code, node)
28 yield parse_python_ast(
29 source_code=source_code,
---> 30 node=n,
31 )
32
vyper/ast_utils.py in parse_python_ast(source_code, node)
76 vyper_class = getattr(vyper_ast, class_name)
77 init_kwargs = _build_vyper_ast_init_kwargs(
---> 78 source_code, node, vyper_class, class_name
79 )
80 return vyper_class(**init_kwargs)
vyper/utils.py in f(*args, **kwargs)
266 @functools.wraps(func)
267 def f(*args, **kwargs):
--> 268 return cast_type(func(*args, **kwargs))
269 return f
270 return yf
vyper/ast_utils.py in _build_vyper_ast_init_kwargs(source_code, node, vyper_class, class_name)
63 parse_python_ast(
64 source_code=source_code,
---> 65 node=val,
66 )
67 )
vyper/ast_utils.py in parse_python_ast(source_code, node)
78 source_code, node, vyper_class, class_name
79 )
---> 80 return vyper_class(**init_kwargs)
81 else:
82 raise SyntaxException(
vyper/ast.py in __init__(self, **kwargs)
30 elif value:
31 raise CompilerPanic(
---> 32 f'Unsupported non-empty value field_name: {field_name}, '
33 f' class: {type(self)} value: {value}'
34 )
CompilerPanic: Unsupported non-empty value field_name: upper, class: <class 'vyper.ast.Slice'> value: <vyper.ast.Num object at 0x7efe06a46d18> Please create an issue.
I don't think it _should_ compile, at least how we have the compiler currently set up, but this is probably a common hangup people are likely to run in to if that is the case, so we should probably have a more helpful error message like Please use 'slice(b, start=0, end=32)' instead.
Maybe we can have tailored messages for specific unsupported syntax, but I also feel like a better default message would be something like this:
SyntaxError: line 31:3 Unsupported python syntax
30
---> 31 b[:32]
----------^
32
Do you mean unsupported Vyper syntax? That's valid python
Yeah, it's valid python syntax but it's unsupported by vyper. To me, unsupported Vyper syntax is confusing because it suggests there's some syntax which we consider to be valid vyper code but it's unsupported by the compiler or something. Maybe just Unsupported syntax is better? My point was really that the default error message could be a lot better. And then we could have a nice API for defining more specific error messages for certain common cases.
Invalid syntax or Unsupported syntax (without mentioning the project) would be better in my book.
:+1: for Unsupported syntax
This was fixed a while ago in one of the AST updates.