Closed kidandcat closed 3 weeks ago
BTW, I solved it just by naming the do
block param, but it took me a while to notice what was the error.
service.environments.do: |env|
It's, unfortunately, a common mistake.
- Is this the intended behaviour?
It is, although it's not really helpful here. The problem is, that the error could be on both sides: the caller provided a block that wants an argument that it won't get, or the callee calls the block but forgets to provide an argument.
In the compiler we would probably print both locations and give the user the information that either one is probably wrong. Since the error here is dynamic, we don't have that option (as easily).
- Shouldn't toit be aware that catch is not calling the block with any arguments and extrapolate that the it refers to the outer loop?
- maybe typing it somehow?
That would be too magic, imho. When looking at a source, you shouldn't need to know the type of targets to know which block an it
resolves too. It should always be the inner-most one.
That said, there are two things we plan to do to make this better:
it
is used inside a block that doesn't get any parameter.Eventually, it would be nice to color the it
in some way that makes it clear where it comes from, but that's not something I see happening in the near future.
Side note: I recommend to use an indentation of 2 (and not 4). The syntax highlighter works better with that indentation.
I'm closing this issue. Not, because I don't agree, but because the two actionable items (better exception handling, and typing) are tracked elsewhere. We do appreciate this kind of feedback, so please keep them coming.
When you refer to
it
inside a nested block, if you intended to refer the outerit
, toit will error because it thinks your inner block expects an argument.Trace:
I'm learning Toit, and this issue got me stuck for a while, at least I would add a warning to the exception trace indicating the user if he is falling into this.
Real use case were this happened: I was doing an http request per item in a List