racket / racket/typed-racket

Regression in type inference for uses of newly defined sub-type in polymorphic functions

Open
#797 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

What version of Racket are you using?

7.2

What program did you run?
#lang typed/racket/base

(struct (X) Wrap ([content : (Option X)]) #:transparent)
(define-new-subtype New-Int (Integer->New-Int Integer))

(: poly (∀ (X) (X → Any) (Wrap X) → Any))
(define (poly f xs) 'ignore)

(: mono : (New-Int → Any) (Wrap New-Int) → Any)
(define (mono f xs) (poly f xs))
What should have happened?

This program type-checks in 7.0. One of the following changes make the program type check in 7.2:

  • Manually instantiate (inst poly New-Int)
  • Define New-Int to just be an alias of Integer instead of sub type
  • Change content's type from Option X to X or Listof X
If you got an error message, please include it here.
; Type Checker: Polymorphic function `poly' could not be applied to arguments:
; Argument 1:
;   Expected: (-> X Any)
;   Given:    (-> New-Int Any)
; Argument 2:
;   Expected: (Wrap X)
;   Given:    (Wrap New-Int)
; 
; Result type:     Any
; Expected result: Any
; 
;   in: (poly f xs)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied #lang typed/racket/base program and inspect the type-checking failure at (poly f xs). Compare inference for Wrap New-Int and the Option X field with the behavior in Racket 7.0. Done means the program type-checks in the normal polymorphic call without manual instantiation or changing the subtype or field type.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.