Merge pull request #1943 from pascalabcnet/lambda_fixes

Lambda fixes
This commit is contained in:
Terky 2019-05-18 21:32:05 +03:00 committed by GitHub
commit 79dacd5f37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 9 deletions

View file

@ -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.

View file

@ -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.

View file

@ -1035,8 +1035,17 @@ namespace SymbolTable
// Нет. Как-то найти глобальное ПИ модуля
while (scope != null && !(scope is UnitInterfaceScope))
{
if (scope is ClassMethodScope)
scope = (scope as ClassMethodScope).DefScope;
if (scope is ClassMethodScope)
{
// aab 17.05.19 begin
// Поправил приоритет поиска для ?System
var classMethodScope = scope as ClassMethodScope;
if (classMethodScope.DefScope != null)
scope = classMethodScope.DefScope;
else
scope = classMethodScope.CurrentLambdaDefScope;
// aab 17.05.19 end
}
else scope = scope.TopScope;
}
if (scope != null)
@ -1155,12 +1164,8 @@ namespace SymbolTable
var defScope = (CurrentArea as ClassMethodScope).DefScope;
if (defScope != null)
{
var defScopeRes = FindAll(defScope, Name, OnlyInType, OnlyInThisClass, defScope);
if (defScopeRes != null && defScopeRes.Count > 0)
{
return defScopeRes;
}
CurrentArea = defScope;
continue;
}
}
}

View file

@ -1179,7 +1179,7 @@ namespace PascalABCCompiler.TreeConverter
// aab 26.04.19
// Здесь topScope записывается именно в CurrentLambdaDefScope, а не в DefScope
// Во всех остальных случаях записывается в DefScope
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.Scope, topScope, null, "lambda " + name); // aab 09.05.19 Временно вернул обратно
SymbolTable.Scope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.Scope, null, topScope, "lambda " + name);
//TODO:сделать static и virtual.
//TODO: interface and implementation scopes.