mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 07:19:22 +00:00
added doc on clashes with variable names
This commit is contained in:
parent
1e93140e24
commit
43e58e6b57
@ -726,6 +726,28 @@ String m(String s, double n) { return s + n; }
|
||||
String m(String s) { return s; }
|
||||
\end{lstlisting}
|
||||
|
||||
Local variables can also clash with the use of a global method. For instance, using the \texttt{alert} global method from the DOM (\texttt{jsweet.dom.Globals.alert}) requires that no local variable hides it. For instance:
|
||||
|
||||
\begin{lstlisting}[language=Java]
|
||||
import static jsweet.dom.Globals.alert;
|
||||
|
||||
[...]
|
||||
|
||||
public void m1(boolean alert) {
|
||||
// JSweet compile error: name clash between parameter and method call
|
||||
alert("test");
|
||||
}
|
||||
|
||||
public void m2() {
|
||||
// JSweet compile error: name clash between local variable and method call
|
||||
String alert = "test";
|
||||
alert(alert);
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
Note that this problem only happens with global functions invocations. With regular static or instance methods, clashes does not occur because the target (which can be implicit) differentiates the method from the variable. For instance:
|
||||
|
||||
|
||||
|
||||
\section{Variable scoping in lambda expressions}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user