Skip to content

fix: sharp/bin/spec gives each setup type of a named block a file of its own - #150

Merged
heyJordanParker merged 2 commits into
masterfrom
fix/spec-split-named
Oct 16, 2026
Merged

heyJordanParker merged 2 commits into
masterfrom
fix/spec-split-named

Conversation

@heyJordanParker

Copy link
Copy Markdown
Owner

Fixes: sharp/bin/spec writes the types of a block's setup into the block's own file when the block names its file, so the one-type-per-file rule of section 27 will refuse required-constructors, which passes today.

This PR changes only the measure, as #147 did. The rule itself comes in the section 27 feature PR.

Problem

#147 gave each type of an example a file of its own, but only for a block that names no file. A block whose first line is a path comment, such as // app/Order.sharp, stayed one file, with its marker's setup inside it. required-constructors is that case: its setup declares public abstract class DatabaseEntity, and its block names app/Order.sharp. With the rule, its run reports:

FAIL §25 required-constructors (docs/spec.md:3383)
  line 7 of the generated app/Order.sharp, from the marker's setup or wrapper: A `.sharp` file declares one type: move `DatabaseEntity` to `DatabaseEntity.sharp`.

Solution

split_types takes $named. A named block's file keeps every type the block writes a line of, as written, so one-type-per-file still shows its error. Each type that only the setup declares goes to the path its namespace and name give, as every other generated file does. The named file is the first part, so it keeps the path and holds the run of a statements block.

sharp/spec-self-test.md gains named-file-setup. Its setup declares Seat, and its block names app/Ticket.sharp. An error in Seat names app/Seat.sharp. docs/architecture/spec-examples.md says how a named block's setup types become files.

Verification

  • The same examples pass and fail. Both runs used the engine and mago built from master 4e4ac5f: Checked 202 examples, ignored 1, and 14 fail before and after. The two full reports are byte for byte the same: diff of them prints nothing. Master fails 14, not 16, since feat: every rule of section 11, generics, compiles, refuses or runs as the spec says #142 made generic-method-inference and type-parameter-bounds pass. The 187 passing examples are below.
  • Self-test: on master's runner, sharp/bin/spec --self-test gives 21 of 22 self-test examples give the problems they expect. named-file-setup fails there with reported, and not expected: line 4 of the generated app/Ticket.sharp, from the marker's setup or wrapper: Invalid return type for method Seat.number: expected int, but found string. On this branch it gives 22 of 22.
  • With the rule: on feat/files, which adds the one-type rule, this runner gives Checked 201 examples, ignored 1, and 14 fail. required-constructors, one-type-per-file and position all pass.
The 187 examples that pass, before and after
access-on-get
any-checks
array-object-replacements
attribute-arguments
backed-enum
bare-name-patterns
behavior-class
bitwise
bool-conditions
braces
capture-and-change
capture-by-reference
change-observers
changed-copy-returned
class-header
class-law
class-members
class-value-equality
class-values
collection-literals
collection-read-methods
collection-write-methods
constructor-call-this
continue-in-condition
conversions
copy-on-write
dot-access
effectful-declarations
element-checks
emit-effect
emit-forms
empty-literals
enum-data-cases
enum-interfaces
enum-map-keys
enum-shapes
environment
environment-module
event-declarations
extension-hidden-member
extension-overloads
extension-static-choice
extension-unused-type-parameter
extensions
extern-declaration
extern-event
extern-event-effects
extern-functions
extern-implementations
field-and-property
file-header
for-of
foreign-class
foreign-constructor
function-fields
function-type-effects
function-types
generic-class-values
generic-extensions
generic-implementation
generic-method-inference
generic-statics
getter-writes
import-rename
impossible-patterns
index-changes
index-rules
inferred-locals
inferred-type-arguments
initial-value-storage
initial-values
initializer-shorthand
int-power
int-to-float
integer-division
interface-defaults
interface-members
is-and-as
is-not-scope
iterables
json-encoding
keyword-members
keyword-names
lambdas
lazy-property
leave-on-null
library-constants
library-functions
lifted-equality
listener-errors
listeners
literal-kinds
map-reads
map-string-keys
map-values
match-coverage
match-forms
method-declarations
method-values
missing-service
module-errors
module-law
module-services
named-arguments
named-constructors
namespace-and-import
naming-cases
narrowing
natural-remove
needless-null-checks
negative-tests
not-or-parentheses
null-defaults
nullable-map-values
nullable-members
nullable-unions
object-type
one-body-per-method
one-dispatcher
one-method-per-name
override-parameter-names
own-namespace-shadows
parameter-members
pattern-locals
pattern-scope
php-trait-defaults
plain-php-calls
plain-php-float-arguments
plain-php-generic-types
plain-php-overrides
plain-php-property-override
plain-php-traits
property-behaviors
property-collections
property-narrowing
property-patterns
property-references
psr-listeners
raw-generic-objects
readonly-by-definition
readonly-cannot-matter
readonly-fields
readonly-last-clause
readonly-overrides
readonly-positions
readonly-stays-readonly
readonly-values
required-constructors
scoped-binding
scoped-listener
sealed-interfaces
self-on-type-parameters
self-parameter
self-return
set-arguments
set-once
set-variable-arguments
spreads
standalone-event
standard-library-import
state-machine-law
static-initial-values
string-joining
struct-changes
struct-equality
struct-parse
struct-parse-object
sub-interface-defaults
super-call
super-calls
template-types
templates
test-module
this-members
tuples
type-parameter-bounds
type-tests
typed-locals
typed-loop-variables
typeof-type-parameters
typeof-types
typeof-values
unchecked-any
union-types
unreachable-statements
virtual-methods
yield

…its own

A block whose first line names its file, as `// app/Order.sharp`, was written
as one file with its marker's setup, so required-constructors put the setup's
DatabaseEntity in app/Order.sharp, which section 27's one-type rule refuses.

split_types takes `$named`: a named block's file keeps every type the block
writes a line of, as written, so one-type-per-file still shows its error, and
each type the setup alone declares goes to the path its namespace and name
give. sharp/spec-self-test.md gains named-file-setup.
@heyJordanParker
heyJordanParker merged commit 830d4aa into master Oct 16, 2026
20 checks passed
heyJordanParker added a commit that referenced this pull request Oct 16, 2026
Problem

#145 was behind master, which gained #142, #143, #144, #146 to #150.
Both sides changed the default names: this branch generates them from
the standard library into `SHARP_CLASSES`, and #143 added `Result` to a
hand-written list and made `Error` a default name nothing shadows.

Solution

One mechanism: `default_classes()` stays `NAMED_EFFECTS` plus the
generated `SHARP_CLASSES`, regenerated from the merged library, which now
holds `Sharp\Error` and `Sharp\Result`. #143's `fixed_default_class`
stays, and `default_classes()` leaves out the class it fixes, so `Error`
is never shadowable while `Result` is.

sharp/mago/crates/names/src/
├── lib.rs                 default_classes and fixed_default_class
├── sharp_classes.rs       regenerated: Error and Result join
└── internal/walker.rs     both imports kept
docs/architecture/slices/23-names-imports.md   Error is the one fixed default name
heyJordanParker added a commit that referenced this pull request Oct 16, 2026
The Results fixture of #143 becomes the Results folder, one type per file, which fixture() loads and its preload
requires in declaration order. Four #143 tests in semantics and the bridge give each type its own file, and hir maps
the new partial-type parse error.
@heyJordanParker
heyJordanParker deleted the fix/spec-split-named branch November 3, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant