ClojureDart
ClojureDart copied to clipboard
Case statement fails when used with a variable
Case statement fails when used with a variable with the following error:
Execution error (AssertionError) at cljd.compiler/emit-case* (compiler.cljc:1600).
Assert failed: (and (symbol? expr) (env expr))
ClojureDart version: 1e38014dcb93dcdb230d125c7d0966556a82d234
Examples:
;; OK
(case :ios
:ios "iOS"
:android "Android"
"not implemented") => "iOS"
(defn case-test
[os]
(case os
:ios "iOS"
:android "Android"
"not implemented"))
(case-test :ios) => "iOS"
;; ERROR
(def os :ios)
(case os
:ios "iOS"
:android "Android"
"not implemented") => Execution error...
(let [the-os :ios]
(case the-os
:ios "iOS"
:android "Android"
"not implemented")) => Execution error...
Currently working around this by using condp
.
Thanks for reporting, we'll take a look
Is this case expression top level?
Yes, it makes it easier to differentiate by platform.
e.g.
(ns app.presentation.reorderable-list-view
(:require app.util.platform :as platform))
(defn android-reorderable-list-view
[args]
(f/widget
...))
(defn ios-reorderable-list-view
[args]
(f/widget
...))
(defn macos-reorderable-list-view
[args]
(f/widget
...))
(def reorderable-list-view
(case platform/os
:android android-reorderable-list-view
:ios ios-reorderable-list-view
:macos macos-reorderable-list-view))
;; elsewhere
(:require [app.presentation.reorderable-list-view :refer [reorderable-list-view]])
Currently compiles correctly.
~~However, case
also fails in the following example:~~
(def a 1)
(defn broken []
(case a
1 "one"
2 "two"
"?"))
Compiling to Dart... @08:46
repl.main
Execution error (AssertionError) at cljd.compiler/emit-case* (compiler.cljc:1616).
Assert failed: (and (symbol? expr) (env expr))
Case statements are failing in the following scenario as well...
(defn acase
[month]
(case month
dart:core.DateTime/may "May"
dart:core.DateTime/june "June"
"????"))
(defn acond
[month]
(condp = month
dart:core.DateTime/may "May"
dart:core.DateTime/june "June"
"????"))
(dart:core/print (acase dart:core.DateTime/may)) ;=> ????
(dart:core/print (acond dart:core.DateTime/june)) ;=> June