]> code.delx.au - gnu-emacs/blobdiff - test/indent/prolog.prolog
* prolog.el: Fix indentation of empty line
[gnu-emacs] / test / indent / prolog.prolog
index 6cb5535fe8df0442dc2f905b83589f1f697a6688..6bf9437b8836e196b882b65d580b7d71a0eb64a5 100644 (file)
@@ -1,5 +1,26 @@
 %% -*- mode: prolog; coding: utf-8; fill-column: 78 -*-
 
+%% bug#21526
+test1 :-
+    (   a ->
+            (   a ->
+                b
+            ;   c
+            )
+    ;   c
+    ).
+
+test2 :-
+    (    a
+    ->   (   a,
+             b
+         ;   c
+         ),
+         b2
+    ;    c1,
+         c2
+    )
+
 %% Testing correct tokenizing.
 foo(X) :- 0'= = X.
 foo(X) :- 8'234 = X.
@@ -48,7 +69,19 @@ subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)) :-
           subst(Y, Y1, [], Bi, Bi1);
       Y1 = Y, Bi1 = Bi),
      %% Perform substitution on the body.
-     subst(X, V, FV, Bi1, Bo)).
+     subst(X, V, FV, Bi1, Bo)),
+    (  X = Y
+    %% If X is equal to Y, X is shadowed, so no subst can take place.
+    -> Y1 = Y, Bo = Bi
+    ;  (member((Y, _), FV)
+        %% If Y appears in FV, it can appear in V, so we need to
+        %% rename it to avoid name capture.
+        -> new_atom(Y, Y1),
+           subst(Y, Y1, [], Bi, Bi1)
+        ; Y1 = Y, Bi1 = Bi),
+       %% Perform substitution on the body.
+       subst(X, V, FV, Bi1, Bo)
+    ).
 subst(X, V, FV, pi(Y, Ti, Bi), pi(Y1, To, Bo)) :-
     subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)).
 subst(X, V, FV, forall(Y, Ti, Bi), forall(Y1, To, Bo)) :-
@@ -200,7 +233,7 @@ elaborate(fix(F,T,B,E), Env, Ee) :-
     elaborate(let(F,T,app(fix,lambda(F,T,B)),E), Env, Ee).
 
 %% elab_bindings(+TS, +Env, -TS).
-%% Applique `elaborate' sur l'environnment de type TS.
+%% Applique `elaborate' sur l'environnement de type TS.
 elab_tenv([], _, []).
 elab_tenv([(X,T)|TS], Env, [(X, Tg)|TSe]) :-
     elaborate(T, Env, Te),