From def7a8a35c1ba0d9d16802fd91ba62b081cafecf Mon Sep 17 00:00:00 2001 From: Madhanika Jayasimha Date: Tue, 1 Aug 2023 10:50:24 -0700 Subject: [PATCH] Fixed null check and default case --- .../logic/signal_width_mismatch_exception.dart | 2 +- lib/src/modules/conditional.dart | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/exceptions/logic/signal_width_mismatch_exception.dart b/lib/src/exceptions/logic/signal_width_mismatch_exception.dart index 424d9fed6..304fb398a 100644 --- a/lib/src/exceptions/logic/signal_width_mismatch_exception.dart +++ b/lib/src/exceptions/logic/signal_width_mismatch_exception.dart @@ -30,6 +30,6 @@ class SignalWidthMismatchException extends RohdException { /// Constructs a new [Exception] for when a dynamic has no width or it could /// not be inferred. SignalWidthMismatchException.forNull(dynamic val) - : super('Could not infer width of value $val.' + : super('Could not infer width of input $val.' ' Please provide a valid width.'); } diff --git a/lib/src/modules/conditional.dart b/lib/src/modules/conditional.dart index cc4b2898a..02fae26ec 100644 --- a/lib/src/modules/conditional.dart +++ b/lib/src/modules/conditional.dart @@ -923,16 +923,16 @@ Logic cases(Logic expression, Map conditions, width ??= inferredWidth; - if (width == null && inferredWidth == null) { - throw SignalWidthMismatchException.forNull(conditionValue); - } - if (width != inferredWidth && inferredWidth != null) { throw SignalWidthMismatchException.forDynamic( conditionValue, width!, inferredWidth); } } + if (width == null) { + throw SignalWidthMismatchException.forNull(conditions); + } + for (final condition in conditions.entries) { if (condition.key is Logic) { if (expression.width != (condition.key as Logic).width) { @@ -963,7 +963,7 @@ Logic cases(Logic expression, Map conditions, [result < condition.value]) ], conditionalType: conditionalType, - defaultItem: defaultValue != null ? [result < defaultValue] : []) + defaultItem: defaultValue != null ? [result < defaultValue] : null) ]); return result;