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

'in' expression for AA not detected as GC usage #18905

Open
dlangBugzillaToGithub opened this issue Nov 5, 2014 · 1 comment
Open

'in' expression for AA not detected as GC usage #18905

dlangBugzillaToGithub opened this issue Nov 5, 2014 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

sinkuupump reported this on 2014-11-05T11:58:48Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=13688

CC List

  • Stanislav Blinov

Description

'in' expression for AA calls KeyType.toHash/opEquals if exist, but not detected as GC usage even if these functions are not @nogc.

Example: (In this case, compiler should require that toHash/opEquals are @nogc.)
struct KeyType
{
	int x;

	size_t toHash() const @safe nothrow
	{
		return x;
	}

	bool opEquals(in KeyType r) const
	{
		return x == r.x;
	}
}

ulong func(ulong[KeyType] aa) @nogc
{
	if (auto p = KeyType(10) in aa) // can call KeyType.toHash/opEquals
		return *p;

	return aa.length;
}
@dlangBugzillaToGithub
Copy link
Author

stanislav.blinov commented on 2021-12-08T16:51:16Z

If we go by the spec: https://dlang.org/spec/garbage.html#op_involving_gc

it explicitly lists AA lookups as GC operations. That being said, AAs outright swallow attributes (see related issue). Regardless, if the specification is correct with regards to GC usage, in this case at the very least `func` shouldn't compile.

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

No branches or pull requests

1 participant