FuelLabs / FuelLabs/sway

Prevent implementation of external types

Open
#4,698 1 comment 0 reactions 0 assignees View on GitHub
bug compiler: frontend language feature team:compiler
Dominant language
Rust
Stars
61.4k
Forks
5.4k
Avg merge
3h 33m
Merged PRs (30d)
4

Description

We currently don't limit implementation of types from outside your package so you can even do something like:

```sway
library;

impl u64 {
pub fn foo() {}
}
```

We should have sensible rules similar to Rust's and generally speaking only permit implementing a trait for a type if either the trait or type were defined in the package.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the compiler code that validates trait implementations and the existing tests for impl declarations. Compare the intended rule with Rust's orphan-rule behavior, then add coverage showing that external type and trait combinations are rejected while permitted implementations still compile.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.