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

objet, recursivité et label optionnel #4185

Closed
vicuna opened this issue Dec 14, 2006 · 2 comments
Closed

objet, recursivité et label optionnel #4185

vicuna opened this issue Dec 14, 2006 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 14, 2006

Original bug ID: 4185
Reporter: jm
Status: closed (set by @garrigue on 2007-01-30T01:51:01Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.09.3
Category: ~DO NOT USE (was: OCaml general)

Bug description

Avec un ocamlc 3.09.3 linuxien, ceci compile parfaitement :

class cla_good (o: cla_good) =
object (self)
method test arg () =
(o#test 42 ()) + arg;
end

mais cela échoue :

class cla_bad (o: cla_bad) =
object (self)
method test ?(arg = 42) () =
(o#test ~arg: 42 ()) + arg;
end

« File "test_bad.ml", line 1, characters 5-108:
The abbreviation cla_bad expands to type < test : ?arg:int -> unit -> int >
but is used with type < test : arg:int -> unit -> int; .. > »

À mon humble avis, cela est anormal.
`arg' passe de label optionnel à label non-optionnel :s

@vicuna
Copy link
Author

vicuna commented Dec 14, 2006

Comment author: ertai

En attendant voici une solution temporaire permettant d'utiliser les labels optionnels.

class cla_tmp (o: cla_tmp) =
object (self)
method test ?(arg = 42) () =
(o#test ?arg:(Some 42) ()) + arg;
end

@vicuna
Copy link
Author

vicuna commented Dec 15, 2006

Comment author: @garrigue

Ce comportement correspond a la section 4.1.2 du manuel: labels optionels et inference. Pendant la definition de cla_tmp, le type cla_tmp n'est connu que comme une variable. Par contre, le type de self est mis a jour, on peut donc ecrire:

class cla_ok (o: 'self) =

object (self : 'self)
  method test ?(arg = 42) () =
    (o#test ~arg: 42 ()) + arg;
end;;

class cla_ok : 'a -> object ('a) method test : ?arg:int -> unit -> int end

@vicuna vicuna closed this as completed Jan 30, 2007
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant