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

Return type annotation with where blocks fail to compile #47919

Closed
ghost opened this issue Dec 18, 2022 · 3 comments
Closed

Return type annotation with where blocks fail to compile #47919

ghost opened this issue Dec 18, 2022 · 3 comments
Labels
parser Language parsing and surface syntax

Comments

@ghost
Copy link

ghost commented Dec 18, 2022

Description

Return type annotation with where blocks fail to compile

fib(x::T)::T where T<:Integer = 
    (x <= 1) ? 
        one(x) :
        fib(x - 2) + fib(x - 1)

However, this works with the function-end syntax

function fib(x::T)::T where T<:Integer
    (x <= 1) ? 
        one(x) :
        fib(x - 2) + fib(x - 1)
end

The error caused in the former case is

ERROR: LoadError: UndefVarError: T not defined

Version Info

Julia Version 1.8.0
Commit 5544a0fab7 (2022-08-17 13:38 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: 12 × AMD Ryzen 5 5500U with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, znver2)
  Threads: 1 on 12 virtual cores

How I installed Julia

My OS package manager (dnf)

@sgaure
Copy link

sgaure commented Dec 18, 2022

There seems to be some ambiguity in the syntax, try some parentheses:

(fib(x::T)::T) where {T<:Integer} = 
           (x <= 1) ? 
               one(x) :
               fib(x - 2) + fib(x - 1)

@KristofferC
Copy link
Member

Dup of #21847 I think.

@brenhinkeller brenhinkeller added the parser Language parsing and surface syntax label Dec 18, 2022
@ghost
Copy link
Author

ghost commented Dec 19, 2022

It does seem to be a dupe of that issue, closing, thanks!

@ghost ghost closed this as completed Dec 19, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

3 participants