Modules create a new global scope, other ways to create scope produce local scope such as let blocks, for loops, functions,… ect. produce local scopes.
A little more investigation shows that this however appears not the reason you were getting the Any
julia> function f()
@code_warntype verts[end].index
end
f (generic function with 2 methods)
julia> f()
Body::Any
18 1 ─ %1 = (Base.getfield)(x, f)::Any │
└── return %1
This seems to meant that it is more related to using @code_warntype on an expression rather then a function.