diff --git a/TestSuite/errors/err0319.pas b/TestSuite/errors/err0319.pas new file mode 100644 index 000000000..fa7ae10be --- /dev/null +++ b/TestSuite/errors/err0319.pas @@ -0,0 +1,6 @@ +type AAA = record s: string[4] end; + +begin + var f := OpenFile&('a.dat'); + //f.Read; +end. \ No newline at end of file diff --git a/TestSuite/lambda_capture_local_vs_field.pas b/TestSuite/lambda_capture_local_vs_field.pas new file mode 100644 index 000000000..36cf9c8b8 --- /dev/null +++ b/TestSuite/lambda_capture_local_vs_field.pas @@ -0,0 +1,24 @@ +type + t1 = class + + static a: integer := 1;//не обязательно статичное поле + + procedure p1; + begin + var a := 2; + var p: procedure := ()->begin + + Assert(a=2); + + end; + + p; + end; + + end; + +begin + + (new t1).p1; + +end. \ No newline at end of file diff --git a/TestSuite/lambda_nonstatic_from_static.pas b/TestSuite/lambda_nonstatic_from_static.pas new file mode 100644 index 000000000..c94beadfe --- /dev/null +++ b/TestSuite/lambda_nonstatic_from_static.pas @@ -0,0 +1,24 @@ +type + t1 = class + + b: byte; + + static procedure p1(b: byte); + begin + + var p: procedure; + p := ()-> + begin + p := ()-> + begin + b := b; + end; + end; + + end; + + end; + +begin + Assert(1=1); +end. \ No newline at end of file diff --git a/bin/Lib/PABCExtensions.pas b/bin/Lib/PABCExtensions.pas index b8d8f89e2..c133613a5 100644 --- a/bin/Lib/PABCExtensions.pas +++ b/bin/Lib/PABCExtensions.pas @@ -5,6 +5,25 @@ unit PABCExtensions; uses PABCSystem; +function GetCurrentLocale: string; +begin + var locale: object; + if __CONFIG__.TryGetValue('locale', locale) then + Result := locale as string + else + Result := 'ru'; +end; + +function GetTranslation(message: string): string; +begin + var cur_locale := GetCurrentLocale(); + var arr := message.Split(new string[1]('!!'), System.StringSplitOptions.None); + if (cur_locale = 'en') and (arr.Length > 1) then + Result := arr[1] + else + Result := arr[0] +end; + //{{{doc: Начало секции подпрограмм для типизированных файлов для документации }}} // ----------------------------------------------------- @@ -35,15 +54,34 @@ begin PABCSystem.Rewrite(Result, fname, en); end; +function ContainsReferenceTypes(t: System.Type): boolean; +begin + if t.IsPrimitive then + Result := False + else if t.IsValueType then + begin + var fa := t.GetFields(System.Reflection.BindingFlags.GetField or System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Public or System.Reflection.BindingFlags.NonPublic); + Result := fa.Any(x->ContainsReferenceTypes(x.FieldType)); + end + else Result := True; +end; + +const + BAD_TYPE_IN_TYPED_FILE = 'Для типизированных файлов нельзя указывать тип элементов, являющийся ссылочным или содержащий ссылочные поля!!Typed file cannot contain elements that are references or contains fields-references'; + /// Открывает типизированный файл и возвращает значение для инициализации файловой переменной function OpenFile(fname: string): file of T; begin + if ContainsReferenceTypes(typeof(T)) then + raise new System.SystemException(GetTranslation(BAD_TYPE_IN_TYPED_FILE)); PABCSystem.Reset(Result, fname); end; /// Создаёт или обнуляет типизированный файл и возвращает значение для инициализации файловой переменной function CreateFile(fname: string): file of T; begin + if ContainsReferenceTypes(typeof(T)) then + raise new System.SystemException(GetTranslation(BAD_TYPE_IN_TYPED_FILE)); var res: file of T; PABCSystem.Rewrite(res, fname); Result := res; @@ -52,12 +90,16 @@ end; /// Открывает типизированный файл в заданной кодировке и возвращает значение для инициализации файловой переменной function OpenFile(fname: string; en: Encoding): file of T; begin + if ContainsReferenceTypes(typeof(T)) then + raise new System.SystemException(GetTranslation(BAD_TYPE_IN_TYPED_FILE)); PABCSystem.Reset(Result, fname, en); end; /// Создаёт или обнуляет типизированный файл в заданной кодировке и возвращает значение для инициализации файловой переменной function CreateFile(fname: string; en: Encoding): file of T; begin + if ContainsReferenceTypes(typeof(T)) then + raise new System.SystemException(GetTranslation(BAD_TYPE_IN_TYPED_FILE)); var res: file of T; PABCSystem.Rewrite(res, fname, en); Result := res;