From 6a23949f07f4eba38086b656e7073ce3bf8cd2fe Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 13 Jun 2025 22:13:00 -0700 Subject: Allow interface methods to have default implementations. (#7439) --- docs/user-guide/06-interfaces-generics.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs/user-guide') diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md index b90bc04ba..1912fcb02 100644 --- a/docs/user-guide/06-interfaces-generics.md +++ b/docs/user-guide/06-interfaces-generics.md @@ -43,8 +43,21 @@ struct MyType : IFoo, IBar uint myMethod2(uint2 x) {...} } ``` + In this case, the definition of `MyType` must satisfy the requirements from both the `IFoo` and `IBar` interfaces by providing both the `myMethod` and `myMethod2` methods. +Interface methods can have a default implementation, which will be used if a conforming type doesn't provide an overriding implementation. For example: + +```slang +interface IFoo +{ + int getVal() { return 0; } +} + +// OK, MyType.getVal() will use the default implementation provided in `IFoo`. +struct MyType : IFoo {} +``` + Generics --------------------- -- cgit v1.2.3