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

Add Type.tambig and make ready to use. #7503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Dec 23, 2017

First commit of #2130. I've checked the PR, and fixing all mentioned issues (1983, 7322, 7549, 8868, 9027) depends on this first if we are to take on the original patch.

I've replaced the handling of isAmbiguous in dmangle and hdrgen with asserts, as I do not know whether they are reachable. See that the type is only used for generating errors, I would suspect not.

@dlang-bot
Copy link
Contributor

dlang-bot commented Dec 23, 2017

Thanks for your pull request, @ibuclaw!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#7503"

src/dmd/mtype.d Outdated Show resolved Hide resolved
src/dmd/expressionsem.d Outdated Show resolved Hide resolved
src/dmd/mtype.d Outdated Show resolved Hide resolved
@WalterBright
Copy link
Member

I don't see in this PR any examples of what an ambiguous type may be, and according to the code no type is ever set to being ambiguous. I can't evaluate what the case for this is.

@ibuclaw
Copy link
Member Author

ibuclaw commented Jan 3, 2018

See the referenced PR.

@JinShil
Copy link
Contributor

JinShil commented Jan 9, 2018

@ibuclaw Would you mind accommodating @WalterBright and adding one of #2130's other commits so he can evaluate this further? IMO this is a very important PR for a couple of reasons, and if this is the right approach (sorry I'm not skilled enough to weigh in on that myself) I'd very much like to move it forward.

@wilzbach
Copy link
Member

wilzbach commented Jan 25, 2018

@ibuclaw Would you mind accommodating @WalterBright and adding one of #2130's other commits so he can evaluate this further?

What's wrong with simply opening #2130 and looking at the bugs it fixes?

(also I rebased this PR)

@andralex
Copy link
Member

andralex commented Mar 7, 2018

ping @WalterBright

{
// Even if is(typeof(func)) is OK, is(typeof(func) Sym) could be NG
if (e.id)
e.error("cannot take ambiguous type");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "cannot take" mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should set result to Type.terror

@@ -1156,6 +1160,14 @@ extern (C++) abstract class Type : RootObject
return true;
}

/**************************
* Returns true if T was resolved ambiguously.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use Ddoc style comments.
  2. What does "ambiguous" mean in this context?

src/dmd/mtype.d Outdated
if (t.isAmbiguous())
{
//printf("typeof exp = %s -> t = %s\n", exp.toChars(), t.toChars());
error(loc, "expression `%s` has ambiguous type", exp.toChars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a much more expressive error message. I doubt the user has any idea what an "ambiguous" type is, and the message doesn't say what the type is. If reasonable, it should also suggest corrective action.

tf.next = rs.exp.type;
if (rs.exp.type.isAmbiguous())
{
rs.error("cannot infer return type from ambiguous expression `%s`", rs.exp.toChars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need more expressive error message, see my other comment

@@ -5334,6 +5357,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
Type t1b = exp.e1.type.toBasetype();
Type tob = exp.to.toBasetype();

if (t1b.isAmbiguous() && exp.e1.implicitConvTo(exp.to) <= MATCH.nomatch)
{
exp.error("cannot cast ambiguous expression `%s` to `%s`", exp.e1.toChars(), exp.to.toChars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types of the two expressions need to be displayed, too, as well as what it means for an expression to be "ambiguous". (Especially because ambiguous expressions are used here, while elsewhere it's ambiguous types.)

// Even if is(typeof(func)) is OK, is(typeof(func) Sym) could be NG
if (e.id)
e.error("cannot take ambiguous type");
if (e.id || e.tspec || (e.tok2 != TOK.reserved && e.tok2 != TOK.function_))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors and no error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants