Create declaration for lambda expressions
AbandonedPublic

Authored by flherne on Dec 20 2016, 11:51 PM.

Details

Reviewers
brauch
Summary

This is an alternative to D3555.

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 = (lamba x: 12)("arg") # a should be int, but is mixed.
BUG: 306212

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"]

The types of arguments were never known, even with default arguments.

Create function declarations for lambdas; this is slightly hacky but allows the use of visitArguments() and addArgumentTypeHints() without modification.

Lambdas do now show up in the outline view, which is not ideal.

Test Plan

Fixes one test. Adds five more, none of which passed before.
No test regressions.

I'll run duchainify over the python3.5 source before pushing.

Diff Detail

Repository
R53 KDevelop: Python Support
Lint
Lint Skipped
Unit
Unit Tests Skipped
flherne updated this revision to Diff 9241.Dec 20 2016, 11:51 PM
flherne retitled this revision from to Create declaration for lambda expressions.
flherne updated this object.
flherne edited the test plan for this revision. (Show Details)
flherne added a reviewer: brauch.
flherne set the repository for this revision to R53 KDevelop: Python Support.
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptDec 20 2016, 11:51 PM
flherne updated this revision to Diff 9242.Dec 20 2016, 11:54 PM

Oops, missed a couple of tests.

In the original patch, I have no idea what setInSymbolTable() actually *does*, it's cargo-culted straight from visitFunctionDefinition(). Please advise me if this is a bad idea. :P

kfunk added a subscriber: kfunk.Dec 21 2016, 12:24 AM
kfunk added inline comments.
duchain/expressionvisitor.cpp
380

Style: d -> decl

parser/ast.h
513

Style: lambda_id -> lambdaId, or lambdaName?

flherne abandoned this revision.Dec 27 2016, 10:29 PM

This crashes for obscure reasons if the body is a comprehension, and the UI effects are irritating. Pushed D3555 instead for 5.1.

Maybe try this approach again if it becomes more useful (e.g. if functions can keep their declaration when passed as an argument).