Skip to content

Better type propagation within object literals #7159

@vicuna

Description

@vicuna

Original bug ID: 7159
Reporter: @alainfrisch
Assigned to: @garrigue
Status: acknowledged (set by @garrigue on 2016-03-02T00:43:12Z)
Resolution: open
Priority: low
Severity: feature
Target version: undecided
Category: typing
Monitored by: @hcarty

Bug description

Compare:

# (("abc", 42) : (int * int));;
Characters 2-7:
  (("abc", 42) : (int * int));;
    ^^^^^
Error: This expression has type string but an expression was expected of type
         int

and

# (object method x = "abc" method y = 42 end : <x: int; y: int>);;
Characters 1-42:
  (object method x = "abc" method y = 42 end : <x: int; y: int>);;
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type < x : string; y : int >
       but an expression was expected of type < x : int; y : int >
       Types for method x are incompatible

It could be useful (for error messages and type-based selection) to propagate types from the context to the method bodies for an object literal.

In case of an immediate annotation on the object literal, one can already put the constraint on "this":

# object(_ : <x: int; y:int>) method x = "abc" method y = 42 end;;
Characters 39-44:
  object(_ : <x: int; y:int>) method x = "abc" method y = 42 end;;
                                         ^^^^^
Error: This expression has type string but an expression was expected of type
         int

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions