From: DeaDDooMER <deaddoomer@deadsoftware.ru>
Date: Tue, 22 Aug 2017 12:33:14 +0000 (+0300)
Subject: Исправлена проверка VAR-параметров-записей
X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=57963798c338b0b73e032e9288003fd462f8b954;p=dsw-obn.git

Исправлена проверка VAR-параметров-записей
---

diff --git a/Test.obn b/Test.obn
index e4eeec3..b9b14ae 100644
--- a/Test.obn
+++ b/Test.obn
@@ -1,15 +1,23 @@
 MODULE Test;
 
 TYPE
-  Rider = RECORD i : INTEGER END;
+  Stream* = POINTER TO Handle;
+  Handle = RECORD END;
 
-PROCEDURE X;
-  VAR
-    r : Rider;
+  Writer* = RECORD END;
+
+  Printer* = RECORD (Writer) END;
+
+VAR
+  s : Stream;
+  o : Writer;
+  out : Printer;
+
+PROCEDURE SetStream(VAR w : Writer; stream : Stream);
 BEGIN
-  r.i := 666;
-END X;
+END SetStream;
 
 BEGIN
-  X;
+  SetStream(o, s);
+  SetStream(out, s);
 END Test.
diff --git a/obn-run-tests.sh b/obn-run-tests.sh
index b9116ff..57756c3 100755
--- a/obn-run-tests.sh
+++ b/obn-run-tests.sh
@@ -92,3 +92,6 @@ maketest Test19
 maketest Test20
 maketest Test21
 maketest Test22
+
+makecomp Test23A
+makefail Test23B
diff --git a/src/main.c b/src/main.c
index 9d471e6..05ea892 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,7 +49,7 @@ open_file(struct string_stack * path, const char * ext, const char * name, const
 
 	size_t len = strlen(fname);
 	res -> source = malloc(len + 1);
-	memcpy(res -> source, fname, len);
+	memcpy(res -> source, fname, len + 1);
 
 	return fp;
 }
diff --git a/src/oberon-type-compat.c b/src/oberon-type-compat.c
index 964f0a0..ab5419d 100644
--- a/src/oberon-type-compat.c
+++ b/src/oberon-type-compat.c
@@ -474,7 +474,7 @@ oberon_is_compatible_var_param(oberon_type_t * Tf, oberon_type_t * Ta)
 	/* фактический параметр может быть указателем любого типа. */
 
 	return oberon_is_some_types(Tf, Ta)
-		|| (oberon_is_record_type(Tf) && oberon_extension_of(Ta, Tf))
+		|| (oberon_is_record_type(Tf) && oberon_extension_of(Tf, Ta))
 		|| (oberon_is_system_byte_type(Tf) && (oberon_is_char_type(Ta) || oberon_is_byte_type(Ta)))
 		|| (oberon_is_array_of_system_byte_type(Tf))
 		|| (oberon_is_system_ptr_type(Tf));
diff --git a/src/oberon.c b/src/oberon.c
index 437e769..4a740d8 100644
--- a/src/oberon.c
+++ b/src/oberon.c
@@ -4535,7 +4535,7 @@ oberon_make_ord_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_
 	}
 	else
 	{
-		expr = oberon_cast_expr(ctx, arg, ctx -> int_type);
+		expr = oberon_cast_expr(ctx, arg, ctx -> shortint_type);
 	}
 	return expr;
 }
diff --git a/tests/Test23A.obn b/tests/Test23A.obn
new file mode 100644
index 0000000..e8cf446
--- /dev/null
+++ b/tests/Test23A.obn
@@ -0,0 +1,25 @@
+MODULE Test23A;
+
+TYPE
+  Stream* = POINTER TO Handle;
+  Handle = RECORD END;
+
+  Writer* = RECORD END;
+
+  Printer* = RECORD (Writer) END;
+
+VAR
+  s : Stream;
+  o : Writer;
+  out : Printer;
+
+PROCEDURE SetStream(VAR w : Writer; stream : Stream);
+BEGIN
+END SetStream;
+
+BEGIN
+  SetStream(o, s);
+  SetStream(out, s);
+END Test23A.
+
+Проверка VAR-параметров-записи. Должно компилироваться.
diff --git a/tests/Test23B.obn b/tests/Test23B.obn
new file mode 100644
index 0000000..518fb03
--- /dev/null
+++ b/tests/Test23B.obn
@@ -0,0 +1,24 @@
+MODULE Test23B;
+
+TYPE
+  Stream* = POINTER TO Handle;
+  Handle = RECORD END;
+
+  Writer* = RECORD END;
+
+  Printer* = RECORD (Writer) END;
+
+VAR
+  s : Stream;
+  o : Writer;
+  out : Printer;
+
+PROCEDURE SetStream(VAR w : Writer; stream : Stream);
+BEGIN
+END SetStream;
+
+BEGIN
+  SetStream(s, s);
+END Test23B.
+
+Проверка VAR-параметров-записи. Должно проваливаться.