Skip to content

Commit

Permalink
Resolve parenthesised expression properly
Browse files Browse the repository at this point in the history
  • Loading branch information
klesun committed Jun 21, 2018
1 parent c574ad8 commit adb505d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/org/klesun/deep_assoc_completion/DeepTypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.psi.*;
import com.jetbrains.php.lang.psi.elements.AssignmentExpression;
import com.jetbrains.php.lang.psi.elements.ParenthesizedExpression;
import com.jetbrains.php.lang.psi.elements.PhpExpression;
import com.jetbrains.php.lang.psi.elements.impl.*;
import org.klesun.deep_assoc_completion.helpers.FuncCtx;
Expand Down Expand Up @@ -51,6 +52,10 @@ public static Opt<L<DeepType>> resolveIn(PsiElement expr, FuncCtx ctx)
.map(ass -> ass.getValue())
.fop(toCast(PhpExpression.class))
.map(val -> ctx.findExprType(val).types)
, Tls.cast(ParenthesizedExpression.class, expr)
.map(par -> par.getArgument())
.fop(toCast(PhpExpression.class))
.map(val -> ctx.findExprType(val).types)
, Tls.cast(ClassConstantReferenceImpl.class, expr)
.map(cst -> L(cst.multiResolve(false))
.map(ref -> ref.getElement())
Expand Down
3 changes: 3 additions & 0 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ private static function testInArray($asd)
}
if (array_intersect([''], $types, ['ASD'])) {

}
if (($types[$i] ?? null) === '') {

}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/src/DeepTest/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,15 @@ public function provideArrayMapKeys()
return $list;
}

public function provideBracketExpression()
{
$dict = ['vova' => 1, 'misha' => 2];
$asd = ($dict ?? null);
$asd[''];
$list[] = [$asd, ['vova' => [], 'misha' => []]];
return $list;
}

//=============================
// following are not implemented yet
//=============================
Expand Down

0 comments on commit adb505d

Please sign in to comment.