Open hasithaa opened 1 year ago
I don't think this is fundamentally an iteration issue. Consider
decimal x = let var d = 1 in d;
This gets a compile-time-error.
Given T x = let var y = E1 in E2
, the type of y
is currently inferred from the type of expression E1
. To make this work we would have to do something completely different.
y
within E2 produces type for y
.y
within E2
is used to infer type for y
in the variable declarationThis is quite different from anything the language does currently. Note that E2 could be arbitrarily complicated and could contain multiple references to y
. There also could be multiple such variables.
This kind of type inference is "infer a type for multiple variables based on how the variables are used in a multiple expressions". This would require a much more sophisticated approach to type inference than what we have currently.
Consider the following example.
query
function signature isfunction query(ParameterizedQuery sqlQuery, typedesc<record {}> rowType) returns stream<rowType, Error?>
.rowType
as part of the return type.By looking at the example, it appeared to be ok and
emp
type should be inferred from LHS from the statement. But this generates a compile-time error (SL Update 3) saying the compiler can't infer the type for therowType
.After analyzing the implementation and spec, We found that this behavior is compliant with spec. It says,
So implementation tries to infer the binding pattern type from the iterator and action invocation in the iterator tries to get it from the current context, which is from the binding pattern, so both fail to infer the type.
A workaround is to use the exact type in the binding pattern. Is there anything we can do to improve this experience?