From 43e58e6b578fc36f06767a3ec584f1ce30c6edae Mon Sep 17 00:00:00 2001 From: Renaud Pawlak Date: Wed, 6 Jan 2016 15:30:07 +0100 Subject: [PATCH] added doc on clashes with variable names --- doc/jsweet-language-specifications.tex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/jsweet-language-specifications.tex b/doc/jsweet-language-specifications.tex index 02a929f6..6635f3a5 100644 --- a/doc/jsweet-language-specifications.tex +++ b/doc/jsweet-language-specifications.tex @@ -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}