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

do not normalize types recursively (#fixes 322) #323

Closed
wants to merge 2 commits into from

Conversation

ilya-klyuchnikov
Copy link
Collaborator

For the recursive_types.erl example, - the problem has been tracked down to recursive normalization of types in typechecker:normalize/2 when normalizing type aliases (user defined types).

Stop recursive normalization is a possible fix against going into infinite loop.

Restricting normalization this way, however, makes type_pattern:f example fail (because the "inner alias" is not expanded/normalized anymore). - Moving it into known_problems then.

known_problems/should_pass/type_pattern.erl: 
The pattern "foo" on line 14 at column 3 doesn't have the type [mychar()]

While recursive_types/unwrap/1 from #322 stops falling into the infinite loop of normalization, it's not treated as well typed by Gradualizer - adding it to known_problems too.

recursive_types.erl: The variable on line 8 at column 24 is expected to have type 
rec(atom()) 
but it has type 
rec(atom()) | {rec, rec(rec(atom()))}

-spec unwrap(rec(rec(atom()))) -> rec(atom()).
unwrap({rec, Elem}) -> Elem.
                       ^^^^

A bit more context about recursive_types example: a similar example is accepted by Typed Racket as well-typed:

#lang typed/racket

(define-type
  (MyRec a)
  (U a (Pair 'rec (MyRec a))))

(: unwrap (-> (MyRec (MyRec Symbol)) (MyRec Symbol)))
(define (unwrap my_rec)
  (match my_rec [(cons 'rec elem) elem]))

Copy link
Owner

@josefs josefs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort @ilya-klyuchnikov . I'm not a big fan making other program fail as a result of this change so I made #324 which supercedes this PR. That PR doesn't fail on currently working programs and it fixed the infinite loop, but it still doesn't accept the program you gave.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradualizer may fall into infinite loop for recursive types.
2 participants