Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007865OCamltypingpublic2018-10-20 20:562018-10-22 15:04
Reporterslindley 
Assigned Totrefis 
PriorityhighSeveritymajorReproducibilityalways
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version4.07.0 
Target VersionFixed in Version 
Summary0007865: type inference for inheritance is broken in OCaml 4.07
DescriptionAttempting to compile the following code

```
class c =
object (o)
  method foo = o
end

class d =
object (o) inherit c
  method bar = fun () ->
    let o = List.fold_right (fun _ o -> o#foo) [] o in
    let o = match [] with | [] -> o in o
end
```

leads to the error

```
File "bug.ml", line 10, characters 34-35:
Error: This expression has type < bar : unit -> 'b; foo : 'a; .. > as 'a
       but an expression was expected of type 'c
       Self type cannot escape its class
```

The problem can be worked around by adding type annotations:

```
class d =
object (o : 'self) inherit c
  method bar = fun () ->
    let o = List.fold_right (fun _ o -> o#foo) [] o in
    let (o : 'self) = match [] with | [] -> o in o
end
```

Additional InformationIn the context of a much larger program (the Links web programming language), we managed to make the compiler crash (even with the type annotation) by invoking another method in the body of the match:

  https://github.com/links-lang/links/issues/407 [^]

It probably wouldn't be too hard to generate a small example for that bug too, but I'm hopeful that fixing the initial typing problem may also fix the compiler crash.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0019421)
trefis (manager)
2018-10-22 14:57

I could indeed reproduce on 4.07 but neither on previous versions, nor on trunk.

Note that one needs to pattern-match on a variant type to be able to get the error message on 4.07, if one uses an other construct (e.g. an if) or matches on a string, everything works fine.

It seems that GPR#1735 ( https://github.com/ocaml/ocaml/pull/1735/ [^] ) fixed the issue, at least for the small reproduction case available on this MPR. I haven't looked into the details of what was going wrong and how this change could have fixed it yet however.

The uncaught exception that you mention looks like it might be yet another issue, and I will try to look into it further in a couple of days.

- Issue History
Date Modified Username Field Change
2018-10-20 20:56 slindley New Issue
2018-10-22 14:57 trefis Note Added: 0019421
2018-10-22 15:04 trefis Assigned To => trefis
2018-10-22 15:04 trefis Status new => assigned


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker