# Julia language server, return type declarations, type stability

**URL:** <https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 30, 2021, 6:41pm UTC](https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827 "2021-12-30T18:41:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guidorice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guidorice/32/32310_2.png) [@guidorice](https://discourse.julialang.org/u/guidorice)\
**Post date:** [December 30, 2021, 6:41pm UTC](https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827/1 "2021-12-30T18:41:58Z")

</div>

👋 I’m totally new to Julia, but have some Rust, Zig and Python background.

I am using the Julia Language Server with VSCode. Even for type-stable functions, vscode does not show the return type of functions. And variables which are the results of functional calls, those types are not inferred either, even for type stable functions. (even for simple functions like from Example.jl)

```julia
hello(who::String) = "Hello, $who"

```

I have read in the manual this passage:

> Return type declarations are **rarely used** in Julia: in general, you should instead write “type-stable” functions in which Julia’s compiler can automatically infer the return type. [Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/functions/#Return-type)

So if writing type-stable functions are the best practice, shouldn’t the Language Server provide some information about variable types, and function return types? It’s quite surprising, having used the Language Server implementations for other languages, including Python.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 30, 2021, 9:19pm UTC](https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827/2 "2021-12-30T21:19:17Z")

</div>

That would be nice, but limited to functions with only one possible input (or output) type (like that of the example). And those are not very common. In general type stability and return types are properties of the funcion and of the input types together.

For example, what should this show?

```julia
f(x) = 2x

```

Or is there a broader picture I’m missing?

---

<div class="post-metadata">

**Author:** ![guidorice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guidorice/32/32310_2.png) [@guidorice](https://discourse.julialang.org/u/guidorice)\
**Post date:** [December 30, 2021, 11:17pm UTC](https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827/3 "2021-12-30T23:17:14Z")

</div>

@lmiq to build on your example:

```python
def f(x):
    return 2 * x

var1 = f(42)
print(var1)

var2 = f(3.14)
print(var2)

var3 = f("greetings")
print(var3)

```

```julia
$ python example.py 
84
6.28
greetingsgreetings

```

Here are the code help popups which the Python language server displays in VSCode:

```julia
# hover on f()
(function) f: (x) -> Any
# hover on var1
(variable) var1: int
# hover on var2:
(variable) var2: float
# hover on var3:
(variable) var3: str

```

---

<div class="post-metadata">

**Author:** ![guidorice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guidorice/32/32310_2.png) [@guidorice](https://discourse.julialang.org/u/guidorice)\
**Post date:** [December 30, 2021, 11:41pm UTC](https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827/4 "2021-12-30T23:41:40Z")

</div>

A slightly different example with Python again, but using type hinting

```python
def foo(b: bool) -> Optional[str]:
    if not b:
        return None
    return 'ok'

# hover over foo: 
# (function) foo: (b: bool) -> str | None

var4 = foo(True)
# hover over var4
# (variable) var4: str | None

```

No doubt there are lots of differences between Python type “hinting” system and Julia’s real type system. I am just trying to wrap my head around how this works 🙂

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 30, 2021, 11:57pm UTC](https://discourse.julialang.org/t/julia-language-server-return-type-declarations-type-stability/73827/5 "2021-12-30T23:57:51Z")

</div>

> [@guidorice](#):
>
> `(variable) var1: int`

That could definitely work, it would be just the reading of the output of `@code_warntype`.

The `Any` of `f()` is misleading there, if the function is type stable. That should be different (not sure how, though).
