Open trocher opened 1 year ago
I took a look into this. This should have been caught in the semantics analysis phase in visit_Assign
(or visit_AnnAssign
) where we validate that the value is of the expected type - e.g.:
https://github.com/vyperlang/vyper/blob/187ab0eec8efbe19ed5046e4e947249e9d43141c/vyper/semantics/analysis/local.py#L244-L254
The reason dynamic arrays of a shorter length are not called is because of the compare_type()
implementation for DArrayT
, where a dynamic array value is considered of the same type if it is of a shorter length (see L269):
https://github.com/vyperlang/vyper/blob/187ab0eec8efbe19ed5046e4e947249e9d43141c/vyper/semantics/types/subscriptable.py#L264-L271
These are my findings so far, but I do not have a good handle on what an appropriate fix is yet. I still think this should be handled at the typechecking phase.
Note that the TypeMismatch
emitted for String
and Bytes
in the same case is in fact emitted from _check_assign_bytes
in the codegen, so even if the exception looks nicer, this probably should also have been caught at type-checking
Version Information
vyper --version
): 0.3.8+commit.d76c6ed2python --version
): 3.8.0What's your issue about?
When trying to use
empty(DynArray[TYPE,x])
whereDynArray[TYPE,y]
is expected givenx<y
, the compiler emits aTypeCheckFailure
instead of exiting with a nice error.How can it be fixed?
I would guess that raising
TypeMismatch
would be more appropriate given that the same behaviour forString
andBytes
make use of it.