lambda syntax became more strict

Issue #87 resolved
Dany Marmur created an issue

Declaring something like this:

TSomeCallback = function (const aElement: JElement; const aFieldName: String; var aData: Variant): Boolean;

procedure SomeMethod(const aXElement: JElement; const aXFieldName: String; var aXData: Variant; const OnSucess: TSomeCallback);

i could previously (on the commit from the 6th of january) do

SomeMethod(lElement, lString, lVariant, lambda => false);

I pulled the latest committ (16th of january 2017). (I had to change scope to protected at @378 in dwsUtils to compile, just FYI.)

Now i get a syntax error stating that "Argument 3 expects type function "TSomeCallback(const aElement: JElement; const aFieldName: String; var aData: Variant): Boolean" instead of "lambda(JElement,String,Variant):Boolean" [line...

Maybe this is intended. Maybe i should remove the "const"s. In any case the "lambda => false" is very neat IMHO.

Comments (6)

  1. Eric Grange repo owner

    Looks like a side-effect from a recent change in const parameters to allow passing the by value rather than by reference for small structures (like a function pointer), the lambda semantic/type inferring needs to be updated.

    I had to change scope to protected at 378 in dwsUtils to compile, just FYI.)

    What was the change for ?

  2. Dany Marmur reporter

    When i compile my little project (most dws units implicitly included) i get:

    [dcc32 Error] dwsSymbolDictionary.pas(526): E2003 Undeclared identifier: 'FCount'
    [dcc32 Error] dwsSymbolDictionary.pas(528): E2003 Undeclared identifier: 'FCapacity'
    [dcc32 Error] dwsSymbolDictionary.pas(531): E2003 Undeclared identifier: 'FBuckets'
    [dcc32 Error] dwsSymbolDictionary.pas(531): E2029 'THEN' expected but identifier 'HashCode' found
    [dcc32 Error] dwsSymbolDictionary.pas(534): E2066 Missing operator or semicolon
    [dcc32 Fatal Error] dwsExprs.pas(118): F2063 Could not compile used unit 'dwsSymbolDictionary.pas'
    

    so i changed from "private" to "protected" in dwsUtils.pas. The members of TSimpleHash<T>. Just to be able to test with the latest commit. Thought i'd mention it. Thought it might be helpful.

  3. Eric Grange repo owner

    Interesting, I am not getting any error in Delphi XE, while the compiler should indeed have complained.

    Pushed a commit with the scope change for now (FWIW the generic will be replaced by a non-generic at some point, both for performance and FreePascal compatibility)

  4. Log in to comment