Skip to content

Commit

Permalink
Fix bug in LogicStructure previousValue (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorbel1 authored Feb 20, 2025
1 parent f31c3a5 commit a260cca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/signals/logic_structure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ class LogicStructure implements Logic {
elements.map((e) => e.value).toList(growable: false).rswizzle();

@override
LogicValue? get previousValue =>
elements.map((e) => e.value).toList(growable: false).rswizzle();
LogicValue? get previousValue => elements.any((e) => e.previousValue == null)
? null
: elements
.map((e) => e.previousValue!)
.toList(growable: false)
.rswizzle();

@override
late final int width = elements.map((e) => e.width).sum;
Expand Down
25 changes: 25 additions & 0 deletions test/logic_structure_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,29 @@ void main() {
SimCompare.checkIverilogVector(mod, vectors);
});
});

test('logicstructure value and previous value', () async {
final s = MyStruct();

final val1 = LogicValue.ofInt(1, 2);
final val2 = LogicValue.ofInt(2, 2);

s.put(val1);

expect(s.value, val1);
expect(s.previousValue, isNull);

var checkRan = false;

Simulator.registerAction(10, () {
s.put(val2);
expect(s.value, val2);
expect(s.previousValue, val1);
checkRan = true;
});

await Simulator.run();

expect(checkRan, isTrue);
});
}

0 comments on commit a260cca

Please sign in to comment.