Bug 306212 - lambda expressions don't get correct type
Summary: lambda expressions don't get correct type
Status: RESOLVED FIXED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: git master
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-03 18:45 UTC by Nicolás Alvarez
Modified: 2016-12-27 22:22 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 5.1.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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