It’s because assignment returns the right-hand operand. In other words, 
x::Float64 
= 5 returns 5, not convert(Float64, 5).

Thus, the type assertions on the last statements of your let blocks 
actually *don’t* make sure that the *return value* is of a certain type.

Try

julia> let
       x = convert(Float64, 5)
       end::Float64
5.0

// T

On Tuesday, July 21, 2015 at 6:03:03 AM UTC+2, Ismael VC wrote:

This was surprising:
>
> julia> versioninfo()
> Julia Version 0.4.0-dev+5491
> Commit cb77503 (2015-06-21 09:45 UTC)
> Platform Info:
>   System: Linux (x86_64-unknown-linux-gnu)
>   CPU: Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
>   WORD_SIZE: 64
>   BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
>   LAPACK: libopenblas
>   LIBM: libopenlibm
>   LLVM: libLLVM-3.3
>
> julia> let
>        x::Float64 = 5
>        end::Float64
> ERROR: TypeError: typeassert: expected Float64, got Int64
>
> julia> let
>        x::UTF8String = "test"
>        end::UTF8String
> ERROR: TypeError: typeassert: expected UTF8String, got ASCIIString
>
>
> ​

Reply via email to