@@ -10,7 +10,7 @@ import type { BuiltInIdentifierConstant } from '../../environments/built-in';
1010import { type IEnvironment , type REnvironmentInformation } from '../../environments/environment' ;
1111import { Identifier , ReferenceType } from '../../environments/identifier' ;
1212import { resolveByName , resolveByNameAnyType } from '../../environments/resolve-by-name' ;
13- import { EdgeType } from '../../graph/edge' ;
13+ import { DfEdge , EdgeType } from '../../graph/edge' ;
1414import type { DataflowGraph } from '../../graph/graph' ;
1515import { onReplacementOperator , type ReplacementOperatorHandlerArgs } from '../../graph/unknown-replacement' ;
1616import { onUnknownSideEffect } from '../../graph/unknown-side-effect' ;
@@ -21,7 +21,7 @@ import { setFrom } from '../values/sets/set-constants';
2121import { resolveNode } from './resolve' ;
2222import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context' ;
2323import type { RSymbol } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol' ;
24- import { RLoopConstructs } from '../../../r-bridge/lang-4.x/ast/model/model' ;
24+ import { RLoopConstructs , RNode } from '../../../r-bridge/lang-4.x/ast/model/model' ;
2525import { RoleInParent } from '../../../r-bridge/lang-4.x/ast/model/processing/role' ;
2626
2727export type ResolveResult = Lift < ValueSet < Value [ ] > > ;
@@ -294,21 +294,7 @@ onReplacementOperator((args: ReplacementOperatorHandlerArgs) => {
294294} ) ;
295295
296296function isNestedInLoop ( node : RNodeWithParent | undefined , ast : AstIdMap ) : boolean {
297- const parent = node ?. info . parent ;
298- if ( node === undefined || ! parent ) {
299- return false ;
300- }
301-
302- const parentNode = ast . get ( parent ) ;
303- if ( parentNode === undefined ) {
304- return false ;
305- }
306-
307- if ( parentNode . type === RType . WhileLoop || parentNode . type === RType . RepeatLoop || parentNode . type === RType . ForLoop ) {
308- return true ;
309- }
310-
311- return isNestedInLoop ( parentNode , ast ) ;
297+ return RNode . iterateParents ( node , ast ) . some ( RLoopConstructs . is ) ;
312298}
313299
314300/**
@@ -368,19 +354,24 @@ export function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadO
368354
369355 const isFn = t === VertexType . FunctionCall ;
370356 const outgoingEdges = graph . outgoingEdges ( id ) ?? [ ] ;
357+ let foundRetuns = false ;
371358 // travel all read and defined-by edges
372359 for ( const [ targetId , { types } ] of outgoingEdges ) {
373360 if ( isFn ) {
374361 if ( types === EdgeType . Returns || types === EdgeType . DefinedByOnCall || types === EdgeType . DefinedBy ) {
375362 queue . add ( targetId , baseEnvironment , cleanFingerprint , false ) ;
376363 }
364+ foundRetuns ||= DfEdge . includesType ( { types } , EdgeType . Returns ) ;
377365 continue ;
378366 }
379367 // currently, they have to be exact!
380368 if ( types === EdgeType . Reads || types === EdgeType . DefinedBy || types === EdgeType . DefinedByOnCall ) {
381369 queue . add ( targetId , baseEnvironment , cleanFingerprint , false ) ;
382370 }
383371 }
372+ if ( isFn && ! foundRetuns ) {
373+ return Top ;
374+ }
384375 }
385376
386377 if ( forceTop || resultIds . length === 0 ) {
@@ -391,7 +382,7 @@ export function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadO
391382 for ( const id of resultIds ) {
392383 const node = idMap . get ( id ) ;
393384 if ( node !== undefined ) {
394- if ( node . info . role === RoleInParent . ParameterDefaultValue ) {
385+ if ( node . info . role === RoleInParent . ParameterDefaultValue || RNode . iterateParents ( node , idMap ) . some ( p => p . info . role === RoleInParent . ParameterDefaultValue ) ) {
395386 return Top ;
396387 }
397388 values . add ( valueFromRNodeConstant ( node ) ) ;
0 commit comments