Skip to content

Missing error for abstract type in var parameter of function definition #6402

@zygoloid

Description

@zygoloid

Description of the bug:

The toolchain accepts var parameters with abstract types in function definitions.

What did you do, or what's a simple way to reproduce the bug?

abstract class A {}
fn F(var a: A) {}

What did you expect to happen?

This example should produce an error, as vars with abstract types do in other contexts.

What actually happened?

Example is accepted; code is generated for F. However, it doesn't seem to be possible to call F, as any call would create an instance of an A.

Any other information, logs, or outputs that you want to share?

We should also consider whether we want to reject abstract classes as parameter types in forward declarations. It seems reasonable to reject:

abstract class A;
fn F(var a: A);

but for a class imported from C++, we don't necessarily know whether it is abstract when we see a forward declaration:

import Cpp inline '''
struct A;
struct B; // #1
struct B { virtual void f() = 0; }; // #2
''';

// Presumably should be OK, we don't know whether A is abstract.
fn F(var a: Cpp.A);
// Should we reject this because B happens to be complete? Or accept,
// as we would if we had only seen #1 and not #2?
fn G(var a: Cpp.B);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions