Skip to content

TFA: converting if block to equivalent switch expression yields weird code #60661

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

Closed
kevmoo opened this issue May 1, 2025 · 1 comment
Closed

Comments

@kevmoo
Copy link
Member

kevmoo commented May 1, 2025

Dart code delta

diff --git a/lib/src/vector_math/matrix2.dart b/lib/src/vector_math/matrix2.dart
index cd102bd..0ed5119 100644
--- a/lib/src/vector_math/matrix2.dart
+++ b/lib/src/vector_math/matrix2.dart
@@ -218,19 +218,12 @@ class Matrix2 {
   @pragma('wasm:prefer-inline')
   @pragma('vm:prefer-inline')
   @pragma('dart2js:prefer-inline')
-  dynamic operator *(dynamic arg) {
-    final Object result;
-    if (arg is double) {
-      result = scaled(arg);
-    } else if (arg is Vector2) {
-      result = transformed(arg);
-    } else if (arg is Matrix2) {
-      result = multiplied(arg);
-    } else {
-      throw ArgumentError(arg);
-    }
-    return result;
-  }
+  dynamic operator *(dynamic arg) => switch (arg) {
+        double() => scaled(arg),
+        Vector2() => transformed(arg),
+        Matrix2() => multiplied(arg),
+        _ => throw ArgumentError(arg)
+      };

TFA delta

@kevmoo
Copy link
Member Author

kevmoo commented May 1, 2025

Nevermind

@kevmoo kevmoo closed this as completed May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant