Open valerauko opened 2 months ago
the warnings are red herrings and are fixed on main
How is color
defined?
If it's a compiler regression it looks like we lost the type of color and thus (m/AlwaysStoppedAnimation color)
is not inferred to the right type.
The most recent change affecting inference is https://github.com/Tensegritics/ClojureDart/commit/4e80ee1ca52fec788f9b5a555e8f44299a67de8c
@valerauko provided form is not enough to repro. Can you share more? At least how color
is introduced.
@cgrand here's a full main.cljd. This works on previous sha but results in error on latest.
(ns repro.main
(:require ["package:flutter/material.dart" :as m]
[cljd.flutter :as f]))
(defn loading
([]
(loading (m/Color. 0xff3c434d)))
([^m/Color color]
(f/widget
m/Center
m/CircularProgressIndicator
.valueColor
(m/AlwaysStoppedAnimation. color))))
(defn main []
(f/run
m/MaterialApp
.home
(f/widget
m/Center
(loading))))
@valerauko e05433c2999af00b19c1ea5c6093f639d1d7d4c5 is the culprit! I wasn't suspecting that. Will fix asap. Have you been able to work around the issue?
For now, not upgrading to latest sha is the "workaround". It works fine on the previous blessed sha and I didn't see any critical changes that would require latest sha, so I can wait for the fix to be released~
The afore-mentioned commit is sound. The expansion of f/widget changed and introduced an extra let.
Thus (m/AlwaysStoppedAnimation. color)
was extracted instead of being inline.
When inline, it happened it stayed inline even in Dart. Thus leaving type inference to Dart.
When extracted, ClojureDart does the type inference and is oblivious to type variables.
(deftest infer-type-args
(let [e (MapEntry (str "a") (count "a"))]
(is (instance? #/(MapEntry String int) e))))
fails currently, saying e is an instance of MapEntry<dynamic, dynamic>
.
Hmm but in my case, color
is explicitly type hinted
the problem is not with color
but with the compiler failing (well not even trying) to infer the parametrized type of (m/AlwaysStoppedAnimation. color)
. As long as there was no let
it was ok because the non-parametrized type never appeared and then the Dart compiler inferred the right one.
I worked around this by changing the offending code as follows
(defn loading
([]
(loading (m/Color. 0xff3c434d)))
([^m/Color color]
(f/widget
m/Center
(m/CircularProgressIndicator
.valueColor (m/AlwaysStoppedAnimation. color)))))
(eg manually added parens around the CircularProgressIndicator so it wouldn't rely on the f/widget expansion)
Obvious workaround in hindsight.
Describe the bug
The offending widget is as follows
Does your problem persist after
clj -M:cljd clean && flutter clean
? YesTo Reproduce After
cljd upgrade
the UI is full of the above exceptionExpected behavior No type cast error
Additional info Not sure if related but there are also two dynamic warnings