Skip to content

Commit

Permalink
Merge pull request #2270 from lf-lang/instance-in-mode
Browse files Browse the repository at this point in the history
Fix NPE bug for instance in mode
  • Loading branch information
lhstrh authored Apr 28, 2024
2 parents 0f9fa03 + 04917ac commit ca250f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/org/lflang/graph/InstantiationGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.lflang.ast.ASTUtils;
import org.lflang.lf.Instantiation;
import org.lflang.lf.Mode;
import org.lflang.lf.Model;
import org.lflang.lf.Reactor;
import org.lflang.lf.ReactorDecl;
Expand Down Expand Up @@ -154,6 +155,12 @@ private void buildGraph(final Instantiation instantiation, final Set<Instantiati
for (final Instantiation inst : reactor.getInstantiations()) {
this.buildGraph(inst, visited);
}
// Also have to look for instantiations inside modes.
for (final Mode mode : reactor.getModes()) {
for (final Instantiation inst : mode.getInstantiations()) {
this.buildGraph(inst, visited);
}
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/C/src/ImportInstanceInMode.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Test that importing from a file with a reactor that is only instantiated in
// a mode does not trigger a NPE.
target C {
timeout: 0 s
}

import B from "lib/InstanceInMode.lf"

main reactor {
b = new B()
}
14 changes: 14 additions & 0 deletions test/C/src/lib/InstanceInMode.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Define a reactor that is only instantiated inside a mode.
target C

reactor U {
reaction(startup) {= =}
}

reactor B {
reaction(startup) {= =}

initial mode A {
u = new U()
}
}

0 comments on commit ca250f1

Please sign in to comment.