manywaypark's Blog
개발, 검색, 함수

'dialyzer'에 해당되는 글 1건

  1. 2020.02.27 Function has no local return

Function has no local return

함수형 언어/Elixir 2020. 2. 27. 20:22 by manywaypark

dialyzer(discrepancy analyzer)는 Erlang의 static analyzer(정적분석도구)이다. type safety가 확보되면 아주 많은 오류를 줄일 수 있다. 그런데 이 좋은 도구인 dialyzer를 사용하다보면 언듯 보기에 멀쩡한 부분에서 "function foo/2 has no local return" 이라는 경고를 만나게 된다.

일단 참고 아티클에서 발췌:

'Function Name/Arity has no local return' is the standard Dialyzer warning emitted whenever a function provably doesn't return anything (other than perhaps raising an exception) because one of the function it calls happens to trip Dialyzer's type error detector or raises an exception itself. When such a thing happens, the set of possible types of values the function could return is empty; it doesn't actually return. This error propagates to the function that called it, giving us the 'no local return' error.

대충 요약하자면 return이 없거나 영원이 return되지 않을 것(crash 등)으로 추측되는 경우 dialyzer에서 이 경고가 나온다는 말인데...

내 경험상 해결 방법은 다음 방법들 중에 하나를 쓰면 된다. 

  1. dialyer에게 type inference hint를 준다. 즉, @spec을 제대로 써주면 해결됨 (dialyer는 좁은 범위를 제시하면 훨씬 똑똑하게 동작함)
  2. error, exception, raise 등이 발생하는 경우(1차적으로 눈에 보이지 않더라도 call stack을 따라 전파됨) return type에 명시적으로 return이 없을 수 있다고 명시한다.
    - Erlang은 no_return()
    - Elixir는 RuntimeError를 try rescue/catch 등의 방법으로 처리

 

ref: https://learnyousomeerlang.com/dialyzer#typing-about-types-of-types

 

Type Specifications and Erlang | Learn You Some Erlang for Great Good!

Hey there, it appears your Javascript is disabled. That's fine, the site works without it. However, you might prefer reading it with syntax highlighting, which requires Javascript! Type Specifications and Erlang Back in Types (or lack thereof), I introduce

learnyousomeerlang.com

happy hackin'

1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

03-29 04:16