# Different result of \`===\` between \`@runtest\` and REPL

**URL:** <https://discourse.julialang.org/t/different-result-of-between-runtest-and-repl/108924>\
**Category:** General Usage\
**Tags:** testing\
**Created:** [January 17, 2024, 7:30pm UTC](https://discourse.julialang.org/t/different-result-of-between-runtest-and-repl/108924 "2024-01-17T19:30:54Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [January 18, 2024, 9:28am UTC](https://discourse.julialang.org/t/different-result-of-between-runtest-and-repl/108924/5 "2024-01-18T09:28:14Z")

</div>

Actually I changed my mind and now think this is intended. From [the manual on scopes](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#local-scope) (emphasis mine):

> A new local scope is introduced by most code blocks (see above [table](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#man-scope-table) for a complete list). If such a block is syntactically nested inside of another local scope, the scope it creates is nested inside of all the local scopes that it appears within, which are all ultimately nested inside of the global scope of the module in which the code is evaluated. \*\*Variables in outer scopes are visible from any scope they contain […] unless there is a local variable with the same name that “shadows” the outer variable of the same name. **This is true even if the outer local is declared after (in the sense of textually below) an inner block**. When we say that a variable “exists” in a given scope, this means that a variable by that name exists in any of the scopes that the current scope is nested inside of, including the current one.  
> […]  
> When `x = <value>` occurs in a local scope, Julia applies the following rules to decide what the expression means based on where the assignment expression occurs and what `x` already refers to at that location:
> 
> 1. **Existing local:** If `x` is _already a local variable_, then the existing local `x` is assigned;
> 2. **Hard scope:** If `x` is _not already a local variable_ and assignment occurs inside of any hard scope construct (i.e. within a `let` block, function or macro body, comprehension, or generator), a new local named `x` is created in the scope of the assignment;

I don’t like all consequences of this (like the example in this thread) but this is the way it is…

Edit: So the correct way to write snippets above is with using `local` inside the inner function:

> [@mkitti](#):
>
> ```julia-repl
> julia> let
> function build_matrix()
> local A = zeros(2,2)
> A[1,2] = A[2,1] = 1
> return A
> end
> A = build_matrix()
> B = build_matrix()
> A === B
> end
> false
> 
> ```

---

_[View the full topic](https://discourse.julialang.org/t/different-result-of-between-runtest-and-repl/108924)._
