private static Void writeKeyVal(Buf b, Str key, Obj? val)
{
if (val == null) writeNull(b, key)
else if (val is Str) writeStr(b, key, val)
else if (val is Date) writeDateTime(b, key, val as DateTime) // convert to DateTime //Compoilation Error!!!!
else if (val is DateTime) writeDateTime(b, key, val)
.....
Does anybody know the story behind the compilation error? The code looks totally fine for me.
Thanks,
go4Sun 8 Aug 2010
sorry,delete this
go4Sun 8 Aug 2010
The following expressions are considered equivalent
obj is Str? => obj is Str
obj as Str => obj as Str?
It's confused.I suggest to forcibly using obj is Str and obj as Str?.
zyhongSun 8 Aug 2010
Thanks! That is a really quick reply. I am new to fantom and have thought this is a small community and I would expect to long delay to get a reply at weekend. I guess I am wrong.
I also think this implicit conversion will confuse some beginners of the language. It should at least give some hint at the error messages.
brianSun 8 Aug 2010
I suspect the error was introduced by issue `http://fantom.org/sidewalk/topic/1127` which made is illegal to use an as expression where a non-nullable was expected. In this case removing the as DateTime should fix the problem (using an implicit cast to DateTime).
It's confused.I suggest to forcibly using obj is Str and obj as Str?.
The expression x as Str evaluates to Str? by definition. It is actually a compile time error to use x as Str?.
How to implement it by method ,Like this obj.is(DateTime), obj.as(DateTime).it is more pretty
ivanMon 9 Aug 2010
go4,
Implementing it as method is acceptable for as (because you'll get almost the same with safe invoke - foo?.as(Bar#) instead of foo as Bar. However with is it gets more uglier - instead of foo is Bar you'll have to write foo?.is(Bar#) ?: false.
heliumMon 9 Aug 2010
foo?.as(Bar#)
is more pretty than
foo as Bar
? I don't think so.
go4Fri 13 Aug 2010
helium.
foo.as(Bar).isOdd() <=> (foo as Bar).isOdd()
perhaps it's not pretty,but more OO.
keilwSat 14 Aug 2010
I can't find the thread, where jodastephen refers to recent news (Java/Oracle) here, but I suggest fostering and supporting non-relational (or controlled by big entities like Ora, IBM or SAP) databases can only be beneficial to Famtom, too.
zyhong Sun 8 Aug 2010
I am trying to compile the mongodb fantom driver and I get this compilation error:
===
D:\fan\fantomongo\fan\bson\BsonWriter.fan(48,27): Invalid args writeDateTime(sys::Buf, sys::Str, sys::DateTime), not (sys::Buf, sys::Str, sys::DateTime?) BUILD FAILED 252ms!
===
This is the declaration of writeDateTime:
This is where the compilation error happen:
.....
Does anybody know the story behind the compilation error? The code looks totally fine for me.
Thanks,
go4 Sun 8 Aug 2010
sorry,delete this
go4 Sun 8 Aug 2010
The following expressions are considered equivalent
It's confused.I suggest to forcibly using
obj is Str
andobj as Str?
.zyhong Sun 8 Aug 2010
Thanks! That is a really quick reply. I am new to fantom and have thought this is a small community and I would expect to long delay to get a reply at weekend. I guess I am wrong.
I also think this implicit conversion will confuse some beginners of the language. It should at least give some hint at the error messages.
brian Sun 8 Aug 2010
I suspect the error was introduced by issue `http://fantom.org/sidewalk/topic/1127` which made is illegal to use an
as
expression where a non-nullable was expected. In this case removing theas DateTime
should fix the problem (using an implicit cast toDateTime
).The expression
x as Str
evaluates toStr?
by definition. It is actually a compile time error to usex as Str?
.liamstask Sun 8 Aug 2010
I just pushed a changeset that updates this: http://bitbucket.org/liamstask/fantomongo/changeset/733012360ad2
go4 Mon 9 Aug 2010
How to implement it by method ,Like this
obj.is(DateTime)
,obj.as(DateTime)
.it is more prettyivan Mon 9 Aug 2010
go4,
Implementing it as method is acceptable for
as
(because you'll get almost the same with safe invoke -foo?.as(Bar#)
instead offoo as Bar
. However withis
it gets more uglier - instead offoo is Bar
you'll have to writefoo?.is(Bar#) ?: false
.helium Mon 9 Aug 2010
is more pretty than
? I don't think so.
go4 Fri 13 Aug 2010
helium.
foo.as(Bar).isOdd() <=> (foo as Bar).isOdd()
perhaps it's not pretty,but more OO.
keilw Sat 14 Aug 2010
I can't find the thread, where jodastephen refers to recent news (Java/Oracle) here, but I suggest fostering and supporting non-relational (or controlled by big entities like Ora, IBM or SAP) databases can only be beneficial to Famtom, too.