struct NoReturn
Overview
Some expressionswon't return to the current scope and therefore have no return type.
This is expressed as the special return typeNoReturn.
Typical examples for non-returning methods and keywords arereturn,exit,raise,next, andbreak.
This is for example useful for deconstructing union types:
string = STDIN.gets
typeof(string) # => String?
typeof(raise "Empty input") # => NoReturn
typeof(string || raise "Empty input") # => String
The compiler recognizes that in case string is Nil, the right hand side of the expressionstring || raisewill be evaluated.
Sincetypeof(raise "Empty input") isNoReturn the executionwould not return to the current scope in that case.
That leaves onlyString as resulting type of the expression.
Every expressionwhose code paths all result inNoReturnwill beNoReturn aswell.
NoReturn does not show up in a union type because itwould essentially be included in every expression's type.
It is only usedwhen an expressionwill never return to the current scope.
NoReturn can be explicitly set as return type of a method or function definition butwill usually be inferred by the compiler.
NOTE This is a pseudo-class provided directly by the Crystal compiler. It cannot be reopened nor overridden.
Defined in:
docs_pseudo_methods.crConstructors
Instance Method Summary
Instance methods inherited from struct Struct
==(other : YAML::Any)==(other) : Bool ==, hash(hasher) hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io : IO) : Nil to_s
Class methods inherited from struct Struct
pre_initialize(address : Pointer) : Nil
pre_initialize
Instance methods inherited from struct Value
==(other : Log::Metadata::Value)==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup
Instance methods inherited from class Object
! : Bool
!,
!=(other)
!=,
!~(other)
!~,
==(other)
==,
===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
from_json(string_or_io : String | IO, root : String)from_json(string_or_io : String | IO) from_json, from_yaml(string_or_io : String | IO) from_yaml