Thread overview
public imports
Dec 05, 2018
Sjoerd Nijboer
Dec 05, 2018
Adam D. Ruppe
Dec 05, 2018
Sjoerd Nijboer
Dec 05, 2018
H. S. Teoh
Dec 05, 2018
Sjoerd Nijboer
Dec 05, 2018
Paul Backus
December 05, 2018
A small question.
Is it intended behaviour that public imports inside function calls fail with the message "Error: found public instead of statement", or is it an underdocumented feature?

void foo()
{
    public import bar;
}
December 05, 2018
On Wednesday, 5 December 2018 at 21:13:29 UTC, Sjoerd Nijboer wrote:
> A small question.
> Is it intended behaviour that public imports inside function calls fail with the message "Error: found public instead of statement", or is it an underdocumented feature?

Looks intended. It doesn't really make sense to have a public import inside a function.
December 05, 2018
On Wednesday, 5 December 2018 at 21:13:29 UTC, Sjoerd Nijboer wrote:
> A small question.
> Is it intended behaviour that public imports inside function calls fail with the message "Error: found public instead of statement", or is it an underdocumented feature?
>
> void foo()
> {
>     public import bar;
> }

An import statment inside a function is already limited to that function's scope, so making it public doesn't really make sense.

That said, the language specification [1] doesn't say anything about this kind of import being an error, so it's definitely underdocumented. The error message is also not as good as it could be.

[1] https://dlang.org/spec/module.html#scoped_imports
December 05, 2018
On Wednesday, 5 December 2018 at 21:21:12 UTC, Adam D. Ruppe wrote:
> Looks intended. It doesn't really make sense to have a public import inside a function.

I was trying to find a weird corner of the language and maybe do something funny with conditional imports.
They don't work in functions, however public imports do work in templates, but act as imports that are only visible in that scope.

I was trying to get some form of persistant import outside of the function/template scope in the module scope, depending on the parameters of the function or template.
I hoped I could find something funny or maybe some usefull trick.
Unfortunately I couldn't :/


December 05, 2018
On Wed, Dec 05, 2018 at 10:57:37PM +0000, Sjoerd Nijboer via Digitalmars-d-learn wrote: [...]
> I was trying to get some form of persistant import outside of the function/template scope in the module scope, depending on the parameters of the function or template.  I hoped I could find something funny or maybe some usefull trick.  Unfortunately I couldn't :/
[...]


Maybe if you described to us exactly what you want to do, we could find a way to do it that doesn't involve language holes that are not guaranteed to work?


T

-- 
Spaghetti code may be tangly, but lasagna code is just cheesy.
December 05, 2018
On Wednesday, 5 December 2018 at 23:18:49 UTC, H. S. Teoh wrote:
> Maybe if you described to us exactly what you want to do, we could find a way to do it that doesn't involve language holes that are not guaranteed to work?

Honestly I don't know.
I was just messing around.
My initial question was, is this a bug or a feature.
For which I got an answer.