Bläddra i källkod

* fixed compiler crash when putting non-constant string in a set expression
(mantis #15288)

git-svn-id: trunk@14367 -

Jonas Maebe 15 år sedan
förälder
incheckning
b9b95a8f73
3 ändrade filer med 30 tillägg och 1 borttagningar
  1. 1 0
      .gitattributes
  2. 3 1
      compiler/ncnv.pas
  3. 26 0
      tests/webtbf/tw15288.pp

+ 1 - 0
.gitattributes

@@ -9493,6 +9493,7 @@ tests/webtbf/tw14849.pp svneol=native#text/plain
 tests/webtbf/tw14929a.pp svneol=native#text/plain
 tests/webtbf/tw14929b.pp svneol=native#text/plain
 tests/webtbf/tw14946.pp svneol=native#text/plain
+tests/webtbf/tw15288.pp svneol=native#text/plain
 tests/webtbf/tw1599.pp svneol=native#text/plain
 tests/webtbf/tw1599b.pp svneol=native#text/plain
 tests/webtbf/tw1633.pp svneol=native#text/plain

+ 3 - 1
compiler/ncnv.pas

@@ -515,9 +515,11 @@ implementation
 
                   stringdef :
                     begin
+                        if (p2.nodetype<>stringconstn) then
+                          Message(parser_e_illegal_expression)
                         { if we've already set elements which are constants }
                         { throw an error                                    }
-                        if ((hdef=nil) and assigned(buildp)) or
+                        else if ((hdef=nil) and assigned(buildp)) or
                           not(is_char(hdef)) then
                           CGMessage(type_e_typeconflict_in_set)
                         else

+ 26 - 0
tests/webtbf/tw15288.pp

@@ -0,0 +1,26 @@
+{ %fail }
+
+program setcrash;
+
+{$mode objfpc}{$H+}
+
+uses
+  Classes, SysUtils;
+
+var
+  AString: String='blabla';
+
+procedure GetKey(var Key: Char);
+begin
+  if Key in ['c', AString] then
+    writeln('OK');
+end;
+
+var
+  AKey: Char;
+begin
+  AKey := 'c';
+  GetKey(AKey);
+end.
+
+