no runtime error, when program doesn't follow golang specifications #1513
-
yaegi does interpret the code, but I'm expecting a runtime error since I executed a program with an unused variable, as it doesn't follow the golang specifications, can anyone please share on why it didn't happen? @mvertes @mpl
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The Go compiler rejects unused variables but yaegi accepts them. This is expected and necessary due to partial or incremental evaluations in the REPL or programatically: in a first eval the variable is created. It may be used only in a second eval (at the next prompt line). This is where a compiler and an interpreter differ fundamentally. If we apply the compiler rule, it harms the interactivity, and forbids incremental eval. The cost of tolerating unused values is only extra memory consumption. |
Beta Was this translation helpful? Give feedback.
The Go compiler rejects unused variables but yaegi accepts them. This is expected and necessary due to partial or incremental evaluations in the REPL or programatically: in a first eval the variable is created. It may be used only in a second eval (at the next prompt line). This is where a compiler and an interpreter differ fundamentally.
If we apply the compiler rule, it harms the interactivity, and forbids incremental eval. The cost of tolerating unused values is only extra memory consumption.