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

-intf flag not respected when type checking implementations against interface files #6736

Closed
vicuna opened this issue Dec 29, 2014 · 4 comments
Labels
Milestone

Comments

@vicuna
Copy link

vicuna commented Dec 29, 2014

Original bug ID: 6736
Reporter: jordojw
Status: closed (set by @xavierleroy on 2016-12-07T10:47:23Z)
Resolution: not a bug
Priority: normal
Severity: minor
OS: OS X
OS Version: Yosemite
Version: 4.02.0
Target version: 4.02.2+dev / +rc1
Category: ~DO NOT USE (was: OCaml general)

Bug description

My fork of the OCaml compiler is slightly in disarray at the moment, so it's entirely possible that I've done something to break the compiler, but when passing
-intf ./blah.customInterfaceExtension

to specify that this file is an interface with a custom extension, ./blah.ml is not checked against it. Instead, it silently passes because it still looks for ./blah.mli and cannot find it. If I pass the -intf-suffix flag to be ".customInterfaceExtension", everything works correctly, but the benefit of -intf is that you can mix your standard .mli files with your custom extensions.

Here is the line in typemod.ml that appears to be the culprit:

Misc.chop_extension_if_any sourcefile ^ !Config.interface_suffix in

It always falls back to the --intf-suffix version of the ml file.

Though, I have a hard time believing that this has never been caught before. On the other hand, the nature of the bug is that compile errors are incorrectly suppressed due to not checking against an interface file at all so that might explain why it hasn't been reported. The most likely explanation is that I've done something horrible to my fork of the compiler, but at the very least this code looks plain wrong/confusing.

Steps to reproduce

Run ocamlc with -intf ./yourFile.customExtension yourFile.ml

Interface type errors are not caught.

@vicuna
Copy link
Author

vicuna commented Jan 6, 2015

Comment author: @damiendoligez

I think this was never caught before because you're slightly outside the intended use for this feature.

I've no idea how hard it will be to fix this.

@vicuna
Copy link
Author

vicuna commented Jan 14, 2015

Comment author: @garrigue

Actually, this doesn't even look like a bug to me: the specification of -intf is that it compiles the following file as an interface. It is nowhere stated that this should register the file to be used as interface for a following module. Of course this specification is too weak for some use cases, this is why there is an -intf-suffix option.
It could be possible to change the semantics, but this looks like a hack to me, because it requires to compile the interface and the implementation simultaneously.

@vicuna
Copy link
Author

vicuna commented Jan 14, 2015

Comment author: jordojw

So you're saying the workaround is to compile each file individually? It would be nice to be able to supply a list of files and somehow indicate which specific file should be treated as the interface for an implementation. I suppose it's low priority, but it was strange how the behavior was different for -intf when passing multiple input files to ocamlc. It was strange that -intf required that I perform several more separate compiler invocations than without -intf. Just a thought.

@vicuna
Copy link
Author

vicuna commented Mar 13, 2015

Comment author: @damiendoligez

The solution is indeed to use -intf-suffix:

ocamlc -intf-suffix .ml2 aaa.ml2 aaa.ml -intf-suffix .ml3 bbb.ml3 bbb.ml

or

ocamlc -intf-suffix .ml2 aaa.ml2 -intf-suffix .ml3 bbb.ml3 aaa.ml bbb.ml

will do what you want.

@vicuna vicuna closed this as completed Dec 7, 2016
@vicuna vicuna added this to the 4.02.2 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 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