Skip to content
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

type declaration ignored when global variable is set #10935

Closed
stevengj opened this issue Apr 21, 2015 · 1 comment
Closed

type declaration ignored when global variable is set #10935

stevengj opened this issue Apr 21, 2015 · 1 comment
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@stevengj
Copy link
Member

var::T = val can be used to declare the type of a local variable, and it is enforced, but this is not true for global var::T = val.

For example, the following enforces the type:

julia> function foo(x)
          local y::Bool = x
       end
foo (generic function with 1 method)

julia> foo("hello")
ERROR: `convert` has no method matching convert(::Type{Bool}, ::ASCIIString)
 in foo at none:2

But this does not:

julia> y = false
false

julia> function foo(x)
          global y::Bool = x
       end
foo (generic function with 1 method)

julia> foo("hello")
"hello"

julia> y
"hello"
@stevengj stevengj added the types and dispatch Types, subtyping and method dispatch label Apr 21, 2015
stevengj added a commit to JuliaLang/IJulia.jl that referenced this issue Apr 21, 2015
@JeffBezanson
Copy link
Member

dup of #964

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

2 participants