@@ -8,7 +8,8 @@ using Test
8
8
# in the initial view (otherwise, you can hit 'w' to toggle "warn" mode).
9
9
# In this case, make sure you know the inferred types for `idx` and `charset`.
10
10
# Once diagnosed, fix the code in src/globals.jl. To fix it, read
11
- # https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-global-variables
11
+ # https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-untyped-global-variables
12
+ # Here you can assume that the value of `charset` never needs to change.
12
13
@test @inferred (getchar (5 )) == ' e' # see `?@inferred`
13
14
# Check `@descend` again at the end to see that you've fixed it!
14
15
# (Chances are you'll have to restart Julia even if you're using Revise; there are some changes
@@ -18,11 +19,8 @@ using Test
18
19
@test get_homedir () == " wrong"
19
20
set_homedir (ENV [" HOME" ])
20
21
@test get_homedir () == ENV [" HOME" ]
21
- # This one will fail. But you can't make the value constant and still update it!
22
- # Find a way to fix it. Hint: `?Ref` or use an array (Refs are like single-element arrays)
23
- # Explanation: the *container* can be constant, but the *contents* can be modified.
24
- # (Think of the container like a box: you can take something out of the box and put something different
25
- # inside it, but the box itself is unchanged.)
26
- # If the container type specifies the type of the contents, Julia's type-inference will be happy.
22
+ # The next one will fail.
23
+ # Be sure you follow the link on global-value type annotations in
24
+ # https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-untyped-global-variables
27
25
@test @inferred (get_homedir ()) == ENV [" HOME" ] # again, this will likely require restarting Julia to test your fix
28
26
end
0 commit comments