Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE bug for instance in mode #2270

Merged
merged 5 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading