Changeset View
Changeset View
Standalone View
Standalone View
duchain/declarationbuilder.cpp
Show First 20 Lines • Show All 358 Lines • ▼ Show 20 Line(s) | |||||
359 | } | 359 | } | ||
360 | 360 | | |||
361 | void DeclarationBuilder::visitWithItem(WithItemAst* node) | 361 | void DeclarationBuilder::visitWithItem(WithItemAst* node) | ||
362 | { | 362 | { | ||
363 | if ( node->optionalVars ) { | 363 | if ( node->optionalVars ) { | ||
364 | // For statements like "with open(f) as x", a new variable must be created; do this here. | 364 | // For statements like "with open(f) as x", a new variable must be created; do this here. | ||
365 | ExpressionVisitor v(currentContext()); | 365 | ExpressionVisitor v(currentContext()); | ||
366 | v.visitNode(node->contextExpression); | 366 | v.visitNode(node->contextExpression); | ||
367 | visitVariableDeclaration<Declaration>(node->optionalVars, nullptr, v.lastType()); | 367 | auto mgrType = v.lastType(); | ||
368 | auto enterType = mgrType; // If we can't find __enter__(), assume it returns `self` like file objects. | ||||
369 | | ||||
370 | static const IndexedIdentifier enterId(KDevelop::Identifier("__enter__")); | ||||
371 | | ||||
372 | DUChainReadLocker lock; | ||||
373 | if ( auto enterFunc = dynamic_cast<FunctionDeclaration*>( | ||||
374 | Helper::accessAttribute(mgrType, enterId, topContext()))) { | ||||
375 | if ( auto enterFuncType = enterFunc->type<FunctionType>() ) { | ||||
376 | enterType = enterFuncType->returnType(); | ||||
brauch: Please check whether the type assigned to this function is indeed a FunctionType, yes it should… | |||||
377 | } | ||||
378 | } | ||||
379 | lock.unlock(); | ||||
380 | // This may be any assignable expression, e.g. `with foo() as bar[3]: ...` | ||||
381 | assignToUnknown(node->optionalVars, enterType); | ||||
368 | } | 382 | } | ||
369 | Python::AstDefaultVisitor::visitWithItem(node); | 383 | Python::AstDefaultVisitor::visitWithItem(node); | ||
370 | } | 384 | } | ||
371 | 385 | | |||
372 | void DeclarationBuilder::visitFor(ForAst* node) | 386 | void DeclarationBuilder::visitFor(ForAst* node) | ||
373 | { | 387 | { | ||
374 | if ( node->iterator ) { | 388 | if ( node->iterator ) { | ||
375 | ExpressionVisitor v(currentContext()); | 389 | ExpressionVisitor v(currentContext()); | ||
▲ Show 20 Lines • Show All 1504 Lines • Show Last 20 Lines |
Please check whether the type assigned to this function is indeed a FunctionType, yes it should be, but it happens sometimes that other code screws this up and then this will crash