[PR #1257] Add Object.toMixin() method #976

Open
opened 2025-12-30 01:28:03 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/apple/pkl/pull/1257
Author: @Mikulas
Created: 10/27/2025
Status: 🔄 Open

Base: mainHead: tomixin


📝 Commits (1)

  • 84e495a Add Object.toMixin() method

📊 Changes

7 files changed (+1055 additions, -5 deletions)

View changed files

pkl-core/src/main/java/org/pkl/core/ast/ObjectToMixinNode.java (+150 -0)
pkl-core/src/main/java/org/pkl/core/stdlib/base/ObjectNodes.java (+41 -0)
pkl-core/src/test/files/LanguageSnippetTests/input/api/objectToMixin.pkl (+339 -0)
pkl-core/src/test/files/LanguageSnippetTests/output/api/objectToMixin.pcf (+218 -0)
📝 pkl-core/src/test/files/LanguageSnippetTests/output/api/reflectedDeclaration.pcf (+290 -4)
📝 pkl-core/src/test/kotlin/org/pkl/core/ReplServerTest.kt (+2 -0)
📝 stdlib/base.pkl (+15 -1)

📄 Description

Adds a toMixin() method to the Object class that converts an Object
into a Mixin function applicable via the pipe operator (|>).

A generic toMixin() method cannot be implemented in user land, so this
implementation provides a native method that properly handles:

  • Property merging and overriding
  • Element appending with correct index offsetting
  • Entry merging with proper key handling
  • Nested object replacement vs amendment semantics

Implementation uses the source Object's enclosing frame to ensure
proper module context for type resolution during member evaluation.

edit: updated from Dynamic to Object


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/apple/pkl/pull/1257 **Author:** [@Mikulas](https://github.com/Mikulas) **Created:** 10/27/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `tomixin` --- ### 📝 Commits (1) - [`84e495a`](https://github.com/apple/pkl/commit/84e495a638cf71c479f478fa2e224cd27255520a) Add Object.toMixin() method ### 📊 Changes **7 files changed** (+1055 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `pkl-core/src/main/java/org/pkl/core/ast/ObjectToMixinNode.java` (+150 -0) ➕ `pkl-core/src/main/java/org/pkl/core/stdlib/base/ObjectNodes.java` (+41 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/input/api/objectToMixin.pkl` (+339 -0) ➕ `pkl-core/src/test/files/LanguageSnippetTests/output/api/objectToMixin.pcf` (+218 -0) 📝 `pkl-core/src/test/files/LanguageSnippetTests/output/api/reflectedDeclaration.pcf` (+290 -4) 📝 `pkl-core/src/test/kotlin/org/pkl/core/ReplServerTest.kt` (+2 -0) 📝 `stdlib/base.pkl` (+15 -1) </details> ### 📄 Description Adds a `toMixin()` method to the `Object` class that converts an `Object` into a `Mixin` function applicable via the pipe operator (`|>`). A generic `toMixin()` method cannot be implemented in user land, so this implementation provides a native method that properly handles: - Property merging and overriding - Element appending with correct index offsetting - Entry merging with proper key handling - Nested object replacement vs amendment semantics Implementation uses the source `Object`'s enclosing frame to ensure proper module context for type resolution during member evaluation. **edit:** updated from `Dynamic` to `Object` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 01:28:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#976