@@ -1735,6 +1735,33 @@ export class TypeInference {
17351735
17361736 getObjectArrayElementType ( expr : Expression ) : string | null {
17371737 const e = expr as ExprBase ;
1738+ if ( e . type === "variable" ) {
1739+ const varName = ( expr as VariableNode ) . name ;
1740+ const rawType = this . st . getRawInterfaceType ( varName ) ;
1741+ if ( rawType && this . getClass ( rawType ) ) return rawType ;
1742+ const resolved = this . resolveExpressionType ( expr ) ;
1743+ if ( resolved && resolved . arrayDepth > 0 && this . getClass ( resolved . base ) ) {
1744+ return resolved . base ;
1745+ }
1746+ return null ;
1747+ }
1748+ if ( e . type === "array" ) {
1749+ const arrayExpr = expr as ArrayNode ;
1750+ const elements = arrayExpr . elements || [ ] ;
1751+ if ( elements . length > 0 ) {
1752+ const firstElem = elements [ 0 ] as ExprBase ;
1753+ if ( firstElem . type === "new" ) {
1754+ const newExpr = elements [ 0 ] as NewNode ;
1755+ const resolvedClassName = this . resolveClassAlias ( newExpr . className ) ;
1756+ if ( this . getClass ( resolvedClassName ) ) return resolvedClassName ;
1757+ }
1758+ const elemResolved = this . resolveExpressionType ( elements [ 0 ] ) ;
1759+ if ( elemResolved && elemResolved . arrayDepth === 0 && this . getClass ( elemResolved . base ) ) {
1760+ return elemResolved . base ;
1761+ }
1762+ }
1763+ return null ;
1764+ }
17381765 if ( e . type === "binary" ) {
17391766 const binExpr = expr as BinaryNode ;
17401767 if ( binExpr . op === "||" || binExpr . op === "??" ) {
@@ -1744,6 +1771,11 @@ export class TypeInference {
17441771 if ( e . type === "method_call" ) {
17451772 const methodExpr = expr as MethodCallNode ;
17461773 const methodObjBase = methodExpr . object as ExprBase ;
1774+ const m = methodExpr . method ;
1775+ if ( m === "filter" || m === "sort" || m === "reverse" || m === "slice" ) {
1776+ const sourceElemType = this . getObjectArrayElementType ( methodExpr . object ) ;
1777+ if ( sourceElemType ) return sourceElemType ;
1778+ }
17471779 if ( methodObjBase . type === "this" ) {
17481780 const className = this . ctx . getCurrentClassName ( ) ;
17491781 if ( className ) {
0 commit comments