Bug 306212

Summary: lambda expressions don't get correct type
Product: [Developer tools] kdev-python Reporter: Nicolás Alvarez <nalvarez>
Component: Language supportAssignee: Sven Brauch <mail>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: git master   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In: 5.1.0
Sentry Crash Report:

Description Nicolás Alvarez 2012-09-03 18:45:28 UTC
Given:
 f = lambda: 4.5
 a = f()

KDev-Python says 'f' is of type 'float', rather than type 'float function()'. This means that 'a' is then of undefined type ('mixed') when it should be 'float'.
Comment 1 Nicolás Alvarez 2012-09-03 18:46:02 UTC
There is no difference if the lambda has parameters.
Comment 2 Francis Herne 2016-12-27 21:54:12 UTC
Git commit a16e2de3f089fa5f13046fad4ea934d33e9bd128 by Francis Herne.
Committed on 27/12/2016 at 20:53.
Pushed by flherne into branch '5.1'.

Lambda expression improvements.

Lambda expressions were given the type of their return expression, e.g.
 `lambda x: 12` has type "int".

That caused calling them to get no or an incorrect return type:
 `a = (lambda x: 12)("arg")`  # a should be int, but is mixed.

They should have a function type instead.

`*args` or `**kwargs` arguments to a lambda were shown as undefined in
 the return expression:
 `lambda *args, **kwargs: args[1] + kwargs["foo"]`

Fixes one test.

Differential Revision: https://phabricator.kde.org/D3555

M  +6    -0    duchain/declarationbuilder.cpp
M  +12   -0    duchain/expressionvisitor.cpp
M  +1    -0    duchain/expressionvisitor.h
M  +0    -1    duchain/tests/pyduchaintest.cpp

https://commits.kde.org/kdev-python/a16e2de3f089fa5f13046fad4ea934d33e9bd128